﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent
Partial Class propertyEntryWeb
    Inherits System.Web.UI.Page

    Private Sub SetTextBoxHints(ByVal TextBox As TextBox, ByVal DefaultText As String)
        TextBox.Attributes.Add("onfocus", "clearText(this,'" & DefaultText & "')")
        TextBox.Attributes.Add("onblur", "resetText(this,'" & DefaultText & "')")
        If TextBox.Text = String.Empty Then
            TextBox.Text = DefaultText
            TextBox.ForeColor = System.Drawing.Color.Silver
        ElseIf TextBox.Text = DefaultText Then
            TextBox.ForeColor = System.Drawing.Color.Silver
        Else
            TextBox.ForeColor = System.Drawing.Color.Black
        End If
    End Sub

    Private Sub LoadProperty(ByVal PropertyId As String, ByVal ListType As String)

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        ' Edit by Tan Chin Teong 20120708
        ' Add CommissionColumn in Database AW_PROPERTY
        ' Alter Table AW_Property Add CommissionRemark varchar(50)

        objDB.dbVariable.SQLString = "SELECT PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, " &
                                    "ListType, RTransactionId, STransactionId, SRAmt, SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, " &
                                    "SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, SLPSF, SLAskAmt, SLAskPSF, " &
                                    "SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, RRPSF, " &
                                    "RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, " &
                                    "RLAmt, RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, " &
                                    "RICreateDate, RIYes, SListerID, RListerID, KeyInOffice, ProjectRemark, PropertyDesc, " &
                                    "SignboardStatus, SignboardWhere, SignboardWhen, SurveySheet, QuitRent, AssessmentBill, " &
                                    "PendingStatus, PendingWho, PendingWhen, PendingWhy, " &
                                    "RentPendingStatus, RentPendingWho, RentPendingWhen, RentPendingWhy, " &
                                    "Tenure, ListHoldExpired, Access, AccessRemark, " &
                                    "Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, " &
                                    "ExclusiveWhen, ExclusiveEndDate, AuthorizeSaleRent, Remark, CommissionRemark, Production1, Production2, Production3, " &
                                    "Admin1, Admin2, Admin3, LAWidth, LALength, LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, " &
                                    "Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, Renovated, RenovatedRemark, " &
                                    "Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, OwnerAddress, ReferLister, " &
                                    "RListStatus, SListStatus, RRelistStatus, SRelistStatus, UpdateDate, UpdateWho, ReferLandlordLister, " &
                                    "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, CONVERT(datetime, CreateDate, 100) as CreateDate, CONVERT(datetime,SCreateDate,100) as SCreateDate, CONVERT(datetime,RCreateDate,100) as RCreateDate, " &
                                    "CPPlanNo, Floor, CompanyName, ViewContact, OtherContact, LandlordCompanyName, LandlordViewContact, LandlordOtherContact, TitleNo, AgentFeedback,AgentFeedbackRent, " &
                                    "SaleGST, RentGST, SaleView, RentView, Latitude, Longitude, SaleRemark, RentRemark " &
                                    "FROM AW_Property " &
                                    "WHERE StatusDelete=0 AND PropertyId=@PropertyId"
        objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
        objDB.FillData(TempDT, "AW_Property", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each ReadRow As Data.DataRow In TempDT.Rows
            lblhidCreateDate.Text = ReadRow.Item("CreateDate").ToString
            If IsDBNull(ReadRow.Item("SCreateDate")) Then
                lblhidSCreateDate.Text = ""
            Else
                lblhidSCreateDate.Text = ReadRow.Item("SCreateDate").ToString
            End If
            If IsDBNull(ReadRow.Item("RCreateDate")) Then
                lblhidRCreateDate.Text = ""
            Else
                lblhidRCreateDate.Text = ReadRow.Item("RCreateDate").ToString
            End If

            lblhidPropertyId.Text = ReadRow.Item("PropertyId").ToString
            lblhidRoadId.Text = ReadRow.Item("RoadId").ToString
            lblhidProjectId.Text = ReadRow.Item("ProjectId").ToString
            lblhidPropertyTypeId.Text = ReadRow.Item("PropertyTypeId").ToString
            txtPropertyType.Text = GetPropertyType(ReadRow.Item("PropertyTypeId").ToString)
            txtUnitNumber.Text = ReadRow.Item("UnitNumber").ToString
            If lblhidISEFP.Text <> "1" Then
                ddlListType.SelectedValue = ReadRow.Item("ListType").ToString
            End If
            'TODO : to display address, ProjectName
            'Get Listype from property listing
            '-IF user access for RENT - Display RC, RR, RL, RI, RLister, Owner as Landlord
            '-IF user access for SALE - Display SC, SR, SL, SI, SLister, Owner as Owner
            If ListType = "2" Then
                RC.Visible = True
                RR.Visible = True
                RL.Visible = True
                RI.Visible = True
                RLister.Visible = True
                RTitle.Visible = True
                SC.Visible = False
                SR.Visible = False
                SL.Visible = False
                SI.Visible = False
                SLister.Visible = False
                sTitle.Visible = False

                divContentLandlord.Visible = False 'Initially is true (landlord for rent)
                divContentOwner.Visible = False

                'rfvtxtLandlordMobile.Enabled = True
                'rfvtxtLandlordName.Enabled = True
                'rfvtxtMobile.Enabled = False
                'rfvtxtName.Enabled = False
            ElseIf ListType = "1" Then
                RC.Visible = False
                RR.Visible = False
                RL.Visible = False
                RI.Visible = False
                RLister.Visible = False
                RTitle.Visible = False
                SC.Visible = True
                SR.Visible = True
                SL.Visible = True
                SI.Visible = True
                SLister.Visible = True
                sTitle.Visible = True
                divContentLandlord.Visible = False
                divContentOwner.Visible = False 'Initially is true (Owner for rent)
                'rfvtxtLandlordMobile.Enabled = False
                'rfvtxtLandlordName.Enabled = False
                'rfvtxtMobile.Enabled = True
                'rfvtxtName.Enabled = True
            ElseIf ListType = "3" Then
                RC.Visible = True
                RR.Visible = True
                RL.Visible = True
                RI.Visible = True
                RLister.Visible = True
                RTitle.Visible = True
                SC.Visible = True
                SR.Visible = True
                SL.Visible = True
                SI.Visible = True
                SLister.Visible = True
                sTitle.Visible = True
                divContentLandlord.Visible = False   'Initially is true (Owner for rent)
                divContentOwner.Visible = False  'Initially is true (Owner for rent)
            End If
            If ReadRow.Item("SListerId").ToString <> String.Empty Then
                lblSLister.Text = getName(ReadRow.Item("SListerId").ToString)
                lblhidSListerId.Text = ReadRow.Item("SListerId").ToString
            End If
            If ReadRow.Item("RListerId").ToString <> String.Empty Then
                lblRLister.Text = getName(ReadRow.Item("RListerId").ToString)
                lblhidRListerId.Text = ReadRow.Item("RListerId").ToString
            End If
            If lblhidStaffType.Text = "2" Then
                btnSListerList.Visible = False
                btnRListerList.Visible = False
            End If
            If ReadRow.Item("SRYes").ToString = "1" Then
                chkSR.Checked = True
                txtSRAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SRAmt"))
                txtSRPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SRPSF"))
                txtSRAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SRAskAmt"))
                txtSRAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SRAskPSF"))
                txtSRCreateDate.Text = Format(ReadRow.Item("SRCreateDate"), "dd-MMM-yyyy")
                lblSRRequired.Visible = True
                rfvtxtSRAmt.Enabled = True
                rfvtxtSRPSF.Enabled = True
                rfvtxtSRAskAmt.Enabled = True
                rfvtxtSRAskPSF.Enabled = True
            End If
            If ReadRow.Item("SCYes").ToString = "1" Then
                chkSC.Checked = True
                txtSCAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SCAmt"))
                txtSCPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SCPSF"))
                txtSCAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SCAskAmt"))
                txtSCAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SCAskPSF"))
                txtSCCreateDate.Text = Format(ReadRow.Item("SCCreateDate"), "dd-MMM-yyyy")
                lblSCRequired.Visible = True
                rfvtxtSCAmt.Enabled = True
                rfvtxtSCPSF.Enabled = True
                rfvtxtSCAskAmt.Enabled = True
                rfvtxtSCAskPSF.Enabled = True
            End If
            If ReadRow.Item("SLYes").ToString = "1" Then
                chkSL.Checked = True
                txtSLAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SLAmt"))
                txtSLPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SLPSF"))
                txtSLAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SLAskAmt"))
                txtSLAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SLAskPSF"))
                txtSLCreateDate.Text = Format(ReadRow.Item("SLCreateDate"), "dd-MMM-yyyy")
                lblSLRequired.Visible = True
                rfvtxtSLAmt.Enabled = True
                rfvtxtSLPSF.Enabled = True
                rfvtxtSLAskAmt.Enabled = True
                rfvtxtSLAskPSF.Enabled = True
            End If
            If ReadRow.Item("SIYes").ToString = "1" Then
                chkSI.Checked = True
                txtSIAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SIAmt"))
                txtSIPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SIPSF"))
                txtSIAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SIAskAmt"))
                txtSIAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("SIAskPSF"))
                txtSICreateDate.Text = Format(ReadRow.Item("SICreateDate"), "dd-MMM-yyyy")
                lblSIRequired.Visible = True
                rfvtxtSIAmt.Enabled = True
                rfvtxtSIPSF.Enabled = True
                rfvtxtSIAskAmt.Enabled = True
                rfvtxtSIAskPSF.Enabled = True
            End If
            If ReadRow.Item("RRYes").ToString = "1" Then
                chkRR.Checked = True
                txtRRAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RRAmt"))
                txtRRPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RRPSF"))
                txtRRAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RRAskAmt"))
                txtRRAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RRAskPSF"))
                txtRRCreateDate.Text = Format(ReadRow.Item("RRCreateDate"), "dd-MMM-yyyy")
                lblRRRequired.Visible = True
                rfvtxtRRAmt.Enabled = True
                rfvtxtRRPSF.Enabled = True
                rfvtxtRRAskAmt.Enabled = True
                rfvtxtRRAskPSF.Enabled = True
            End If
            If ReadRow.Item("RCYes").ToString = "1" Then
                chkRC.Checked = True
                txtRCAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RCAmt"))
                txtRCPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RCPSF"))
                txtRCAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RCAskAmt"))
                txtRCAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RCAskPSF"))
                txtRCCreateDate.Text = Format(ReadRow.Item("RCCreateDate"), "dd-MMM-yyyy")
                lblRCRequired.Visible = True
                rfvtxtRCAmt.Enabled = True
                rfvtxtRCPSF.Enabled = True
                rfvtxtRCAskAmt.Enabled = True
                rfvtxtRCAskPSF.Enabled = True
            End If
            If ReadRow.Item("RLYes").ToString = "1" Then
                chkRL.Checked = True
                txtRLAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RLAmt"))
                txtRLPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RLPSF"))
                txtRLAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RLAskAmt"))
                txtRLAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RLAskPSF"))
                txtRLCreateDate.Text = Format(ReadRow.Item("RLCreateDate"), "dd-MMM-yyyy")
                lblRLRequired.Visible = True
                rfvtxtRLAmt.Enabled = True
                rfvtxtRLPSF.Enabled = True
                rfvtxtRLAskAmt.Enabled = True
                rfvtxtRLAskPSF.Enabled = True
            End If
            If ReadRow.Item("RIYes").ToString = "1" Then
                chkRI.Checked = True
                txtRIAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RIAmt"))
                txtRIPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RIPSF"))
                txtRIAskAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RIAskAmt"))
                txtRIAskPSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("RIAskPSF"))
                txtRICreateDate.Text = Format(ReadRow.Item("RICreateDate"), "dd-MMM-yyyy")
                lblRIRequired.Visible = True
                rfvtxtRIAmt.Enabled = True
                rfvtxtRIPSF.Enabled = True
                rfvtxtRIAskAmt.Enabled = True
                rfvtxtRIAskPSF.Enabled = True
            End If
            If ReadRow.Item("KeyInOffice").ToString = "1" Then
                chkKeyInOffice.Checked = True
            End If
            txtProjectRemark.Text = ReadRow.Item("ProjectRemark").ToString
            txtPropertyDesc.Text = ReadRow.Item("PropertyDesc").ToString
            If ReadRow.Item("SignboardStatus").ToString = "1" Then
                chkSignboard.Checked = True
                If ReadRow.Item("SignboardWhen").ToString = "" Then
                    txtSignboardDate.Text = ""
                Else
                    txtSignboardDate.Text = Format(ReadRow.Item("SignboardWhen"), "dd-MMM-yyyy")
                End If
                If ReadRow.Item("SignboardWhere").ToString = "" Then
                    txtSignboardWhere.Text = ""
                Else
                    txtSignboardWhere.Text = ReadRow.Item("SignboardWhere").ToString
                End If
                'txtSignboardDate.Visible = True
                'txtSignboardWhere.Visible = True
                SetTextBoxHints(txtSignboardWhere, "Where")
                SetTextBoxHints(txtSignboardDate, "Date")
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "SignboardFunction", "CheckSignboard();", True)
            End If
            txtSurveySheet.Text = ReadRow.Item("SurveySheet").ToString
            txtQuitRent.Text = ReadRow.Item("QuitRent").ToString
            txtAssessmentBill.Text = ReadRow.Item("AssessmentBill").ToString

            'Edited By tanchinteong 20130110
            If ReadRow.Item("AgentFeedback").ToString = "" Then
                AgentFeedbackDDList.SelectedValue = 7
            Else
                AgentFeedbackDDList.SelectedValue = Convert.ToInt16(ReadRow.Item("AgentFeedback").ToString)
            End If

            'Edited By tanchinteong 20130913
            If ReadRow.Item("AgentFeedbackRent").ToString = "" Then
                AgentFeedbackRentDDList.SelectedValue = 7
            Else
                AgentFeedbackRentDDList.SelectedValue = Convert.ToInt16(ReadRow.Item("AgentFeedbackRent").ToString)
            End If
            'Edited by tanchinteong 20150308
            If ReadRow.Item("SaleGST").ToString = "1" Then
                rbSaleGSTYes.Checked = True
            Else
                rbSaleGSTNo.Checked = True
            End If

            If ReadRow.Item("RentGST").ToString = "1" Then
                rbRentGSTYes.Checked = True
            Else
                rbRentGSTNo.Checked = True
            End If

            If ReadRow.Item("SaleView").ToString = "1" Then
                rbSaleViewYes.Checked = True
            Else
                rbSaleViewNo.Checked = True
            End If

            If ReadRow.Item("RentView").ToString = "1" Then
                rbRentViewYes.Checked = True
            Else
                rbRentViewNo.Checked = True
            End If

            If ReadRow.Item("SaleRemark").ToString = "" Then
                txtSaleRemark.Text = ""
            Else
                txtSaleRemark.Text = ReadRow.Item("SaleRemark").ToString
            End If
            If ReadRow.Item("RentRemark").ToString = "" Then
                txtRentRemark.Text = ""
            Else
                txtRentRemark.Text = ReadRow.Item("RentRemark").ToString
            End If

            If ReadRow.Item("Latitude").ToString = "" Then
                txtLatitude.Text = ""
            Else
                txtLatitude.Text = ReadRow.Item("Latitude").ToString
            End If
            If ReadRow.Item("Longitude").ToString = "" Then
                txtLongitude.Text = ""
            Else
                txtLongitude.Text = ReadRow.Item("Longitude").ToString
            End If

            If ReadRow.Item("PendingStatus").ToString = "1" Then
                chkPendingStatus.Checked = True
                If ReadRow.Item("PendingWho").ToString = "" Then
                    txtPendingWho.Text = ""
                Else
                    txtPendingWho.Text = ReadRow.Item("PendingWho").ToString
                End If
                If ReadRow.Item("PendingWhen").ToString = "" Then
                    txtPendingWhen.Text = ""
                Else
                    txtPendingWhen.Text = Format(ReadRow.Item("PendingWhen"), "dd-MMM-yyyy")
                End If
                If ReadRow.Item("PendingWhy").ToString = "" Then
                    txtPendingWhy.Text = ""
                Else
                    txtPendingWhy.Text = ReadRow.Item("PendingWhy").ToString
                End If

                SetTextBoxHints(txtPendingWho, "Who")
                SetTextBoxHints(txtPendingWhen, "Date")
                SetTextBoxHints(txtPendingWhy, "Why")
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "PendingFunction", "CheckPending();", True)
            End If

            If ReadRow.Item("RentPendingStatus").ToString = "1" Then
                chkRentPendingStatus.Checked = True
                If ReadRow.Item("RentPendingWho").ToString = "" Then
                    txtRentPendingWho.Text = ""
                Else
                    txtRentPendingWho.Text = ReadRow.Item("RentPendingWho").ToString
                End If
                If ReadRow.Item("RentPendingWhen").ToString = "" Then
                    txtRentPendingWhen.Text = ""
                Else
                    txtRentPendingWhen.Text = Format(ReadRow.Item("RentPendingWhen"), "dd-MMM-yyyy")
                End If
                If ReadRow.Item("RentPendingWhy").ToString = "" Then
                    txtRentPendingWhy.Text = ""
                Else
                    txtRentPendingWhy.Text = ReadRow.Item("RentPendingWhy").ToString
                End If

                SetTextBoxHints(txtRentPendingWho, "Who")
                SetTextBoxHints(txtRentPendingWhen, "Date")
                SetTextBoxHints(txtRentPendingWhy, "Why")
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "PendingFunction", "CheckPending();", True)
            End If

            If ReadRow.Item("Tenure").ToString = "" Or ReadRow.Item("Tenure").ToString = "0" Then
                ddlTenure.SelectedValue = "0"
            Else
                ddlTenure.SelectedValue = ReadRow.Item("Tenure").ToString
            End If
            If ReadRow.Item("Tenure").ToString = "2" Then '--Listhold
                txtListholdExpired.Text = ReadRow.Item("ListHoldExpired").ToString
                SetTextBoxHints(txtListholdExpired, "Leasehold Expired")
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "ListholdFunction", "checkTenure();", True)
            End If
            If ReadRow.Item("Access").ToString = "" Or ReadRow.Item("Access").ToString = "0" Then
                ddlAccess.SelectedValue = "0"
            Else
                ddlAccess.SelectedValue = ReadRow.Item("Access").ToString
            End If
            txtAccessRemark.Text = ReadRow.Item("AccessRemark").ToString
            SetTextBoxHints(txtAccessRemark, "Remark")
            If ReadRow.Item("Condition").ToString = "" Or ReadRow.Item("Condition").ToString = "0" Then
                ddlCondition.SelectedValue = 0
            Else
                ddlCondition.SelectedValue = ReadRow.Item("Condition").ToString
            End If
            txtConditionRemark.Text = ReadRow.Item("ConditionRemark").ToString
            SetTextBoxHints(txtConditionRemark, "Remark")
            If ReadRow.Item("Facing").ToString = "" Or ReadRow.Item("Facing").ToString = "0" Then
                ddlFacing.SelectedValue = "0"
            Else
                ddlFacing.SelectedValue = ReadRow.Item("Facing").ToString
            End If
            If ReadRow.Item("Zoning").ToString = "" Or ReadRow.Item("Zoning").ToString = "0" Then
                ddlZoning.SelectedValue = "0"
            Else
                ddlZoning.SelectedValue = ReadRow.Item("Zoning").ToString
            End If
            txtZoningRemark.Text = ReadRow.Item("ZoningRemark").ToString
            SetTextBoxHints(txtZoningRemark, "Remark")
            txtRoom.Text = ReadRow.Item("Room").ToString
            txtBathroom.Text = ReadRow.Item("Bathroom").ToString
            If ReadRow.Item("BestBuy").ToString = "1" Then
                chkBestBuy.Checked = True
            End If
            If ReadRow.Item("ExclusiveStatus").ToString = "1" Then
                chkExclusiveStatus.Checked = True
                If ReadRow.Item("ExclusiveEndDate").ToString = "" Then
                    txtExclusiveEndDate.Text = ""
                Else
                    txtExclusiveEndDate.Text = Format(ReadRow.Item("ExclusiveEndDate"), "dd-MMM-yyyy")
                End If
                If ReadRow.Item("ExclusiveWhen").ToString = "" Then
                    txtExclusiveWhen.Text = ""
                Else
                    txtExclusiveWhen.Text = Format(ReadRow.Item("ExclusiveWhen"), "dd-MMM-yyyy")
                End If
                If ReadRow.Item("ExclusiveWho").ToString = "" Then
                    txtExclusiveWho.Text = ""
                Else
                    txtExclusiveWho.Text = ReadRow.Item("ExclusiveWho").ToString
                End If
                'txtExclusiveEndDate.Visible = True
                'txtExclusiveWhen.Visible = True
                'txtExclusiveWho.Visible = True
                SetTextBoxHints(txtExclusiveWho, "Who")
                SetTextBoxHints(txtExclusiveWhen, "When")
                SetTextBoxHints(txtExclusiveEndDate, "End Date")
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "ExclusiveFunction", "checkExclusive();", True)
            End If
            If ReadRow.Item("AuthorizeSaleRent").ToString = "1" Then
                chkAuthorizeSaleRent.Checked = True
            End If
            txtRemark.Text = ReadRow.Item("Remark").ToString
            txtCommissionRemark.Text = ReadRow.Item("CommissionRemark").ToString
            txtProduction1.Text = ReadRow.Item("Production1").ToString
            txtProduction2.Text = ReadRow.Item("Production2").ToString
            txtProduction3.Text = ReadRow.Item("Production3").ToString
            txtAdmin1.Text = ReadRow.Item("Admin1").ToString
            txtAdmin2.Text = ReadRow.Item("Admin2").ToString
            txtadmin3.Text = ReadRow.Item("Admin3").ToString
            txtLALength.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LALength"))
            txtLASF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LASF"))
            txtACRE.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LASF") / 43560.0)
            txtLAWidth.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LAWidth"))
            txtBULength.Text = String.Format("{0:#,##0.00}", ReadRow.Item("BULength"))
            txtBUSF.Text = String.Format("{0:#,##0.00}", ReadRow.Item("BUSF"))
            txtBUWidth.Text = String.Format("{0:#,##0.00}", ReadRow.Item("BUWidth"))
            txtFloorLoad.Text = ReadRow.Item("FloorLoad").ToString
            txtSECMK.Text = ReadRow.Item("SECMK").ToString
            txtCeiling.Text = ReadRow.Item("Ceiling").ToString
            txtTerrain.Text = ReadRow.Item("Terrain").ToString
            txtDistrict.Text = ReadRow.Item("District").ToString
            txtLot.Text = ReadRow.Item("Lot").ToString
            txtPhase.Text = ReadRow.Item("Phase").ToString
            If ReadRow.Item("Furnished").ToString = "" Or ReadRow.Item("Furnished").ToString = "0" Then
                ddlFurnished.SelectedValue = "0"
            Else
                ddlFurnished.SelectedValue = ReadRow.Item("Furnished").ToString
            End If
            txtFurnished.Text = ReadRow.Item("FurnishedRemark").ToString
            SetTextBoxHints(txtFurnished, "Remark")

            If ReadRow.Item("Renovated").ToString = "" Or ReadRow.Item("Renovated").ToString = "0" Then
                ddlRenovated.SelectedValue = "0"
            Else
                ddlRenovated.SelectedValue = ReadRow.Item("Renovated").ToString
            End If
            txtRenovated.Text = ReadRow.Item("RenovatedRemark").ToString
            SetTextBoxHints(txtRenovated, "Remark")

            If ReadRow.Item("ReferLister").ToString = "1" Then
                chkReferLister.Checked = True
            End If

            txtName.Text = ReadRow.Item("OwnerName").ToString
            txtMobile.Text = ReadRow.Item("OwnerMobile").ToString
            txtPhone.Text = ReadRow.Item("OwnerPhone").ToString
            txtFax.Text = ReadRow.Item("OwnerFax").ToString
            txtEmail.Text = ReadRow.Item("OwnerEmail").ToString
            txtAddress.Text = ReadRow.Item("OwnerAddress").ToString

            If ReadRow.Item("ReferLandlordLister").ToString = "1" Then
                chkLandlordReferLister.Checked = True
            End If

            txtLandlordName.Text = ReadRow.Item("LandlordName").ToString
            txtLandlordMobile.Text = ReadRow.Item("LandlordMobile").ToString
            txtLandlordPhone.Text = ReadRow.Item("LandlordPhone").ToString
            txtLandlordFax.Text = ReadRow.Item("LandlordFax").ToString
            txtLandlordEmail.Text = ReadRow.Item("LandlordEmail").ToString
            txtLandlordAddress.Text = ReadRow.Item("LandlordAddress").ToString

            'Added by : Daniel Lee
            'Date : 30-Sept-2011
            'Purpose : Add additional column
            txtCPPlanNo.Text = ReadRow.Item("CPPlanNo").ToString
            txtFloor.Text = ReadRow.Item("Floor").ToString
            txtCompanyName.Text = ReadRow.Item("CompanyName").ToString
            txtViewingContact.Text = ReadRow.Item("ViewContact").ToString
            txtOtherContact.Text = ReadRow.Item("OtherContact").ToString

            'Added by : minginn
            'Date : 22/11/2011
            'Purpose : Additional column
            txtLandlordCompanyName.Text = ReadRow.Item("LandlordCompanyName").ToString
            txtLandlordViewingContact.Text = ReadRow.Item("LandlordViewContact").ToString
            txtLandlordOtherContact.Text = ReadRow.Item("LandlordOtherContact").ToString
            txtTitleNo.Text = ReadRow.Item("TitleNo").ToString

            'Edited by tanchinteong @20130114 
            'To disable changing of landloard info by non-lister
            If lblhidStaffType.Text = "2" Then
                If Session("DirectFromPropertyView") Is Nothing = False Then
                    If Session("DirectFromPropertyView").ToString = "YES" Then
                        If lblhidRListerId.Text <> lblhidStaffId.Text Then
                            'txtLandlordName.ReadOnly = True
                            'txtLandlordCompanyName.ReadOnly = True
                            'txtLandlordMobile.ReadOnly = True
                            'txtLandlordPhone.ReadOnly = True
                            'txtLandlordViewingContact.ReadOnly = True
                            'txtLandlordEmail.ReadOnly = True
                        End If
                        If lblhidSListerId.Text <> lblhidStaffId.Text Then
                            'txtName.ReadOnly = True
                            'txtCompanyName.ReadOnly = True
                            'txtMobile.ReadOnly = True
                            'txtPhone.ReadOnly = True
                            'txtViewingContact.ReadOnly = True
                            'txtEmail.ReadOnly = True
                        End If
                    End If
                End If
            End If

        Next
    End Sub

    Private Sub DisplayBothDetails()
        If ddlListType.SelectedValue = "3" Then
            RC.Visible = True
            RR.Visible = True
            RL.Visible = True
            RI.Visible = True
            RLister.Visible = True
            RTitle.Visible = True
            SC.Visible = True
            SR.Visible = True
            SL.Visible = True
            SI.Visible = True
            SLister.Visible = True
            sTitle.Visible = True
            divContentLandlord.Visible = True
            divContentOwner.Visible = True
            'rfvtxtLandlordMobile.Enabled = True
            'rfvtxtLandlordName.Enabled = True
            'rfvtxtMobile.Enabled = True
            'rfvtxtName.Enabled = True
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        lblhidStaffId.Text = Request.QueryString("userid")
        'If Session("StaffId") Is Nothing Then
        '    Response.Redirect("Default.aspx")

        'Else
        '    lblhidStaffId.Text = Session("StaffId").ToString
        '    lblhidStaffType.Text = Session("StaffType").ToString
        'End If

        'If (lblhidStaffType.Text = "4" Or lblhidStaffType.Text = "6") Then
        '    Response.Redirect("Dashboard.aspx")
        'End If


        lblReqRoadName.Visible = False
        lblReqProjectName.Visible = False
        'ImageButtonEditAddress.Visible = False

        If Not Page.IsPostBack Then

            'CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            SetTextBoxHints(txtSignboardWhere, "Where")
            SetTextBoxHints(txtSignboardDate, "Date")
            SetTextBoxHints(txtPendingWho, "Who")
            SetTextBoxHints(txtPendingWhen, "Date")
            SetTextBoxHints(txtPendingWhy, "Why")
            SetTextBoxHints(txtListholdExpired, "Leasehold Expired")
            SetTextBoxHints(txtExclusiveWho, "Who")
            SetTextBoxHints(txtExclusiveWhen, "When")
            SetTextBoxHints(txtExclusiveEndDate, "End Date")
            SetTextBoxHints(txtRenovated, "Remark")
            SetTextBoxHints(txtFurnished, "Remark")
            SetTextBoxHints(txtAccessRemark, "Remark")
            SetTextBoxHints(txtConditionRemark, "Remark")
            SetTextBoxHints(txtZoningRemark, "Remark")

            'Dim ListType As String
            If Not Request.QueryString("id") Is Nothing Then
                pnlPreEntry.Visible = False
                pnlEntry.Visible = True
                ImageButtonEditAddress.Visible = False

                lblhidPropertyId.Text = Request.QueryString("id")
                lblhidListType.Text = Request.QueryString("ListType")
                'Me.Session.Remove("tp")
                LoadProperty(lblhidPropertyId.Text, lblhidListType.Text)
                GetAddress()
                GetProjectName()
                If lblhidStaffType.Text = "1" Or lblhidStaffType.Text = "5" Then
                    ImageButtonEditAddress.Visible = True
                    btnUpdatePreEntry.Visible = True
                    btnSubmitPreEntry.Visible = False
                    DisplayBothDetails()
                End If
                If lblhidStaffType.Text = "3" Then
                    pnlOwnerInfo.Visible = False
                End If
            Else
                pnlPreEntry.Visible = True
                pnlEntry.Visible = False
                ImageButtonEditAddress.Visible = False
                GetddlCountry()
                GetddlState(ddlCountry.SelectedValue)
                GetddlLocation(ddlState.SelectedValue)

                'divContentOwner.Visible = True
                divContentOwner.Attributes.Add("style", "display:block")
            End If
        Else
            'post back

        End If

    End Sub

    Private Sub ClearAllFields()
        ddlCountry.SelectedValue = ""
        ddlState.SelectedValue = ""
        ddlLocation.SelectedValue = ""
        txtRoadName.Text = String.Empty
        lblhidRoadId.Text = String.Empty
        txtProjectName.Text = String.Empty
        lblhidProjectId.Text = String.Empty
        txtUnitNumber.Text = String.Empty
        lblUnitNumber.Text = String.Empty
        ddlListType.SelectedValue = ""
        lblhidListType.Text = String.Empty
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        If lblhidListType.Text = "1" Then   '--Sale
            If chkSC.Checked Or chkSR.Checked Or chkSL.Checked Or chkSI.Checked Then
                lblListingError.Visible = False
            Else
                lblListingError.Visible = True
                Page.ClientScript.RegisterStartupScript(Me.[GetType](), "anchor", "location.hash = '#Lister';", True)
                Exit Sub
            End If
        ElseIf lblhidListType.Text = "2" Then   '--rent
            If chkRC.Checked Or chkRR.Checked Or chkRL.Checked Or chkRI.Checked Then
                lblListingError.Visible = False
            Else
                lblListingError.Visible = True
                Page.ClientScript.RegisterStartupScript(Me.[GetType](), "anchor", "location.hash = '#Lister';", True)
                Exit Sub
            End If
        ElseIf lblhidListType.Text = "3" Then
            If chkSC.Checked Or chkSR.Checked Or chkSL.Checked Or chkSI.Checked Or chkRC.Checked Or chkRR.Checked Or chkRL.Checked Or chkRI.Checked Then
                lblListingError.Visible = False
            Else
                lblListingError.Visible = True
                Page.ClientScript.RegisterStartupScript(Me.[GetType](), "anchor", "location.hash = '#Lister';", True)
                Exit Sub
            End If
        End If
        If lblhidPropertyId.Text = "" Then
            If CheckPropertyExistence(lblhidListType.Text) Then
                lblMsgError.Text = "The property already listed!"
                divError.Visible = True
                Exit Sub
            End If
        End If
        'insert
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        'Dim 'objDBLocal As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))

        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            'objDBLocal.OpenConnection()
            'objDBLocal.InitDbTrans()

            objDB.AddParameter("PropertyTypeId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidPropertyTypeId.Text))
            objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            objDB.AddParameter("STransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            If chkSR.Checked Then
                'Added @ 2/4/2011 by minginn to provide a quick solution to handle required date field error
                If txtSRCreateDate.Text = "" Then
                    txtSRCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("SRAmt", Data.SqlDbType.Decimal, CDbl(txtSRAmt.Text))
                objDB.AddParameter("SRPSF", Data.SqlDbType.Decimal, CDbl(txtSRPSF.Text))
                objDB.AddParameter("SRAskAmt", Data.SqlDbType.Decimal, CDbl(txtSRAskAmt.Text))
                objDB.AddParameter("SRAskPSF", Data.SqlDbType.Decimal, CDbl(txtSRAskPSF.Text))
                objDB.AddParameter("SRCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSRCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("SRYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("SRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("SRYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkSC.Checked Then
                If txtSCCreateDate.Text = "" Then
                    txtSCCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("SCAmt", Data.SqlDbType.Decimal, CDbl(txtSCAmt.Text))
                objDB.AddParameter("SCPSF", Data.SqlDbType.Decimal, CDbl(txtSCPSF.Text))
                objDB.AddParameter("SCAskAmt", Data.SqlDbType.Decimal, CDbl(txtSCAskAmt.Text))
                objDB.AddParameter("SCAskPSF", Data.SqlDbType.Decimal, CDbl(txtSCAskPSF.Text))
                objDB.AddParameter("SCCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSCCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("SCYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("SCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("SCYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkSL.Checked Then
                If txtSLCreateDate.Text = "" Then
                    txtSLCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("SLAmt", Data.SqlDbType.Decimal, CDbl(txtSLAmt.Text))
                objDB.AddParameter("SLPSF", Data.SqlDbType.Decimal, CDbl(txtSLPSF.Text))
                objDB.AddParameter("SLAskAmt", Data.SqlDbType.Decimal, CDbl(txtSLAskAmt.Text))
                objDB.AddParameter("SLAskPSF", Data.SqlDbType.Decimal, CDbl(txtSLAskPSF.Text))
                objDB.AddParameter("SLCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSLCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("SLYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("SLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("SLYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkSI.Checked Then
                If txtSICreateDate.Text = "" Then
                    txtSICreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("SIAmt", Data.SqlDbType.Decimal, CDbl(txtSIAmt.Text))
                objDB.AddParameter("SIPSF", Data.SqlDbType.Decimal, CDbl(txtSIPSF.Text))
                objDB.AddParameter("SIAskAmt", Data.SqlDbType.Decimal, CDbl(txtSIAskAmt.Text))
                objDB.AddParameter("SIAskPSF", Data.SqlDbType.Decimal, CDbl(txtSIAskPSF.Text))
                objDB.AddParameter("SICreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSICreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("SIYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("SIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("SICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("SIYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkRR.Checked Then
                If txtRRCreateDate.Text = "" Then
                    txtRRCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, CDbl(txtRRAmt.Text))
                objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, CDbl(txtRRPSF.Text))
                objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, CDbl(txtRRAskAmt.Text))
                objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, CDbl(txtRRAskPSF.Text))
                objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtRRCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkRC.Checked Then
                If txtRCCreateDate.Text = "" Then
                    txtRCCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, CDbl(txtRCAmt.Text))
                objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, CDbl(txtRCPSF.Text))
                objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, CDbl(txtRCAskAmt.Text))
                objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, CDbl(txtRCAskPSF.Text))
                objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtRCCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkRL.Checked Then
                If txtRLCreateDate.Text = "" Then
                    txtRLCreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, CDbl(txtRLAmt.Text))
                objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, CDbl(txtRLPSF.Text))
                objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, CDbl(txtRLAskAmt.Text))
                objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, CDbl(txtRLAskPSF.Text))
                objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtRLCreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
            End If
            If chkRI.Checked Then
                If txtRICreateDate.Text = "" Then
                    txtRICreateDate.Text = Format(Now(), "dd-MMM-yyyy")
                End If
                objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, CDbl(txtRIAmt.Text))
                objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, CDbl(txtRIPSF.Text))
                objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, CDbl(txtRIAskAmt.Text))
                objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, CDbl(txtRIAskPSF.Text))
                objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtRICreateDate.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
            End If
            If lblSLister.Text <> String.Empty Then
                objDB.AddParameter("SListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidSListerId.Text))
            Else
                objDB.AddParameter("SListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            End If
            If lblRLister.Text <> String.Empty Then
                objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRListerId.Text))
            Else
                objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            End If
            If chkKeyInOffice.Checked Then
                objDB.AddParameter("KeyInOffice", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("KeyInOffice", Data.SqlDbType.TinyInt, 0)
            End If
            If txtProjectRemark.Text <> String.Empty Then
                objDB.AddParameter("ProjectRemark", Data.SqlDbType.NVarChar, txtProjectRemark.Text.Trim)
            Else
                objDB.AddParameter("ProjectRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtPropertyDesc.Text <> String.Empty Then
                objDB.AddParameter("PropertyDesc", Data.SqlDbType.NVarChar, txtPropertyDesc.Text.Trim)
            Else
                objDB.AddParameter("PropertyDesc", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If chkSignboard.Checked Then
                objDB.AddParameter("SignboardStatus", Data.SqlDbType.TinyInt, 1)
                If txtSignboardWhere.Text <> "Where" Then
                    objDB.AddParameter("SignboardWhere", Data.SqlDbType.NVarChar, txtSignboardWhere.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("SignboardWhere", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtSignboardDate.Text <> "Date" Then
                    objDB.AddParameter("SignboardWhen", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSignboardDate.Text, "dd-MMM-yyyy", Nothing))
                Else
                    objDB.AddParameter("SignboardWhen", Data.SqlDbType.DateTime, DBNull.Value)
                End If
            Else
                objDB.AddParameter("SignboardStatus", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("SignboardWhere", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("SignboardWhen", Data.SqlDbType.DateTime, DBNull.Value)
            End If
            If txtSurveySheet.Text <> String.Empty Then
                objDB.AddParameter("SurveySheet", Data.SqlDbType.NVarChar, txtSurveySheet.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("SurveySheet", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtQuitRent.Text <> String.Empty Then
                objDB.AddParameter("QuitRent", Data.SqlDbType.NVarChar, txtQuitRent.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("QuitRent", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtAssessmentBill.Text <> String.Empty Then
                objDB.AddParameter("AssessmentBill", Data.SqlDbType.NVarChar, txtAssessmentBill.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("AssessmentBill", Data.SqlDbType.NVarChar, DBNull.Value)
            End If

            'Edit by tanchinteong 20130110
            If AgentFeedbackDDList.SelectedValue = 7 Then
                objDB.AddParameter("AgentFeedback", Data.SqlDbType.Int, DBNull.Value)
            Else
                objDB.AddParameter("AgentFeedback", Data.SqlDbType.Int, AgentFeedbackDDList.SelectedValue)
            End If

            'Edit by tanchinteong 20150308
            If rbSaleViewYes.Checked Then
                objDB.AddParameter("SaleView", Data.SqlDbType.TinyInt, 1)
            ElseIf rbSaleViewNo.Checked Then
                objDB.AddParameter("SaleView", Data.SqlDbType.TinyInt, 0)
            Else
                objDB.AddParameter("SaleView", Data.SqlDbType.TinyInt, 1)
            End If

            If rbRentViewYes.Checked Then
                objDB.AddParameter("RentView", Data.SqlDbType.TinyInt, 1)
            ElseIf rbRentViewNo.Checked Then
                objDB.AddParameter("RentView", Data.SqlDbType.TinyInt, 0)
            Else
                objDB.AddParameter("RentView", Data.SqlDbType.TinyInt, 1)
            End If

            If rbSaleGSTYes.Checked Then
                objDB.AddParameter("SaleGST", Data.SqlDbType.TinyInt, 1)
            ElseIf rbSaleGSTNo.Checked Then
                objDB.AddParameter("SaleGST", Data.SqlDbType.TinyInt, 0)
            Else
                objDB.AddParameter("SaleGST", Data.SqlDbType.TinyInt, 0)
            End If

            If rbRentGSTYes.Checked Then
                objDB.AddParameter("RentGST", Data.SqlDbType.TinyInt, 1)
            ElseIf rbRentGSTNo.Checked Then
                objDB.AddParameter("RentGST", Data.SqlDbType.TinyInt, 0)
            Else
                objDB.AddParameter("RentGST", Data.SqlDbType.TinyInt, 0)
            End If

            If txtSaleRemark.Text <> String.Empty Then
                objDB.AddParameter("SaleRemark", Data.SqlDbType.NVarChar, Trim(txtSaleRemark.Text))
            Else
                objDB.AddParameter("SaleRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtRentRemark.Text <> String.Empty Then
                objDB.AddParameter("RentRemark", Data.SqlDbType.NVarChar, Trim(txtRentRemark.Text))
            Else
                objDB.AddParameter("RentRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If

            If txtLongitude.Text <> String.Empty Then
                objDB.AddParameter("Longitude", Data.SqlDbType.Decimal, Convert.ToDecimal(txtLongitude.Text))
            Else
                objDB.AddParameter("Longitude", Data.SqlDbType.Decimal, 0)
            End If
            If txtLatitude.Text <> String.Empty Then
                objDB.AddParameter("Latitude", Data.SqlDbType.Decimal, Convert.ToDecimal(txtLatitude.Text))
            Else
                objDB.AddParameter("Latitude", Data.SqlDbType.Decimal, 0)
            End If

            If chkPendingStatus.Checked Then
                objDB.AddParameter("PendingStatus", Data.SqlDbType.TinyInt, 1)
                If txtPendingWho.Text <> "Who" Then
                    objDB.AddParameter("PendingWho", Data.SqlDbType.NVarChar, txtPendingWho.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("PendingWho", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtPendingWhen.Text <> "Date" Then
                    objDB.AddParameter("PendingWhen", Data.SqlDbType.DateTime, DateTime.ParseExact(txtPendingWhen.Text, "dd-MMM-yyyy", Nothing))
                Else
                    objDB.AddParameter("PendingWhen", Data.SqlDbType.DateTime, DBNull.Value)
                End If
                If txtPendingWhy.Text <> "Why" Then
                    objDB.AddParameter("PendingWhy", Data.SqlDbType.NVarChar, txtPendingWhy.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("PendingWhy", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
            Else
                objDB.AddParameter("PendingStatus", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("PendingWho", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PendingWhen", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("PendingWhy", Data.SqlDbType.NVarChar, DBNull.Value)
            End If

            'Edit by tanchinteong 20130913
            If AgentFeedbackRentDDList.SelectedValue = 7 Then
                objDB.AddParameter("AgentFeedbackRent", Data.SqlDbType.Int, DBNull.Value)
            Else
                objDB.AddParameter("AgentFeedbackRent", Data.SqlDbType.Int, AgentFeedbackRentDDList.SelectedValue)
            End If

            If chkRentPendingStatus.Checked Then
                objDB.AddParameter("RentPendingStatus", Data.SqlDbType.TinyInt, 1)
                If txtRentPendingWho.Text <> "Who" Then
                    objDB.AddParameter("RentPendingWho", Data.SqlDbType.NVarChar, txtRentPendingWho.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("RentPendingWho", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtRentPendingWhen.Text <> "Date" Then
                    objDB.AddParameter("RentPendingWhen", Data.SqlDbType.DateTime, DateTime.ParseExact(txtRentPendingWhen.Text, "dd-MMM-yyyy", Nothing))
                Else
                    objDB.AddParameter("RentPendingWhen", Data.SqlDbType.DateTime, DBNull.Value)
                End If
                If txtRentPendingWhy.Text <> "Why" Then
                    objDB.AddParameter("RentPendingWhy", Data.SqlDbType.NVarChar, txtRentPendingWhy.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("RentPendingWhy", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
            Else
                objDB.AddParameter("RentPendingStatus", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RentPendingWho", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("RentPendingWhen", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RentPendingWhy", Data.SqlDbType.NVarChar, DBNull.Value)
            End If



            objDB.AddParameter("Tenure", Data.SqlDbType.TinyInt, ddlTenure.SelectedValue)
            If ddlTenure.SelectedValue = "2" Then '--Leasehold
                If txtListholdExpired.Text <> "Leasehold Expired" Then
                    objDB.AddParameter("ListHoldExpired", Data.SqlDbType.Int, CInt(txtListholdExpired.Text.Trim))
                Else
                    objDB.AddParameter("ListHoldExpired", Data.SqlDbType.Int, DBNull.Value)
                End If
            Else
                objDB.AddParameter("ListHoldExpired", Data.SqlDbType.Int, DBNull.Value)
            End If
            If ddlAccess.SelectedIndex <> 0 Then
                objDB.AddParameter("Access", Data.SqlDbType.TinyInt, CInt(ddlAccess.SelectedValue))
            Else
                objDB.AddParameter("Access", Data.SqlDbType.TinyInt, DBNull.Value)
            End If
            If txtAccessRemark.Text <> "Remark" Then
                objDB.AddParameter("AccessRemark", Data.SqlDbType.NVarChar, txtAccessRemark.Text.Trim)
            Else
                objDB.AddParameter("AccessRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If ddlCondition.SelectedIndex <> 0 Then
                objDB.AddParameter("Condition", Data.SqlDbType.TinyInt, CInt(ddlCondition.SelectedValue))
            Else
                objDB.AddParameter("Condition", Data.SqlDbType.TinyInt, DBNull.Value)
            End If
            If txtConditionRemark.Text <> "Remark" Then
                objDB.AddParameter("ConditionRemark", Data.SqlDbType.NVarChar, txtConditionRemark.Text.Trim)
            Else
                objDB.AddParameter("ConditionRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If ddlFacing.SelectedIndex <> 0 Then
                objDB.AddParameter("Facing", Data.SqlDbType.TinyInt, CInt(ddlFacing.SelectedValue))
            Else
                objDB.AddParameter("Facing", Data.SqlDbType.TinyInt, DBNull.Value)
            End If
            objDB.AddParameter("Zoning", Data.SqlDbType.TinyInt, CInt(ddlZoning.SelectedValue))
            If txtZoningRemark.Text <> "Remark" Then
                objDB.AddParameter("ZoningRemark", Data.SqlDbType.NVarChar, txtZoningRemark.Text.Trim)
            Else
                objDB.AddParameter("ZoningRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            objDB.AddParameter("Room", Data.SqlDbType.Int, CInt(txtRoom.Text.Trim))
            objDB.AddParameter("Bathroom", Data.SqlDbType.Int, CInt(txtBathroom.Text.Trim))
            If chkBestBuy.Checked Then
                objDB.AddParameter("BestBuy", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("BestBuy", Data.SqlDbType.TinyInt, 0)
            End If
            If chkExclusiveStatus.Checked Then
                objDB.AddParameter("ExclusiveStatus", Data.SqlDbType.TinyInt, 1)
                If txtExclusiveWho.Text <> "Who" Then
                    objDB.AddParameter("ExclusiveWho", Data.SqlDbType.NVarChar, txtExclusiveWho.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("ExclusiveWho", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtExclusiveWhen.Text <> "When" Then
                    objDB.AddParameter("ExclusiveWhen", Data.SqlDbType.DateTime, DateTime.ParseExact(txtExclusiveWhen.Text, "dd-MMM-yyyy", Nothing))
                Else
                    objDB.AddParameter("ExclusiveWhen", Data.SqlDbType.DateTime, DBNull.Value)
                End If
                If txtExclusiveEndDate.Text <> "End Date" Then
                    objDB.AddParameter("ExclusiveEndDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtExclusiveEndDate.Text, "dd-MMM-yyyy", Nothing))
                Else
                    objDB.AddParameter("ExclusiveEndDate", Data.SqlDbType.DateTime, DBNull.Value)
                End If
            Else
                objDB.AddParameter("ExclusiveStatus", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("ExclusiveWho", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("ExclusiveWhen", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("ExclusiveEndDate", Data.SqlDbType.DateTime, DBNull.Value)
            End If
            If chkAuthorizeSaleRent.Checked Then
                objDB.AddParameter("AuthorizeSaleRent", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("AuthorizeSaleRent", Data.SqlDbType.TinyInt, 0)
            End If
            If txtRemark.Text <> String.Empty Then
                objDB.AddParameter("Remark", Data.SqlDbType.NVarChar, txtRemark.Text.Trim)
            Else
                objDB.AddParameter("Remark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtCommissionRemark.Text <> String.Empty Then
                objDB.AddParameter("CommissionRemark", Data.SqlDbType.NVarChar, txtCommissionRemark.Text.Trim)
            Else
                objDB.AddParameter("CommissionRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtProduction1.Text <> String.Empty Then
                objDB.AddParameter("Production1", Data.SqlDbType.Decimal, CDbl(txtProduction1.Text.Trim))
                objDB.AddParameter("Production2", Data.SqlDbType.Decimal, CDbl(txtProduction2.Text.Trim))
                objDB.AddParameter("Production3", Data.SqlDbType.Decimal, CDbl(txtProduction3.Text.Trim))
            Else
                objDB.AddParameter("Production1", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("Production2", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("Production3", Data.SqlDbType.Decimal, DBNull.Value)
            End If
            If txtAdmin1.Text <> String.Empty Then
                objDB.AddParameter("Admin1", Data.SqlDbType.Decimal, CDbl(txtAdmin1.Text.Trim))
                objDB.AddParameter("Admin2", Data.SqlDbType.Decimal, CDbl(txtAdmin2.Text.Trim))
                objDB.AddParameter("Admin3", Data.SqlDbType.Decimal, CDbl(txtadmin3.Text.Trim))
            Else
                objDB.AddParameter("Admin1", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("Admin2", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("Admin3", Data.SqlDbType.Decimal, DBNull.Value)
            End If
            objDB.AddParameter("LAWidth", Data.SqlDbType.Decimal, CDbl(txtLAWidth.Text.Trim))
            objDB.AddParameter("LALength", Data.SqlDbType.Decimal, CDbl(txtLALength.Text.Trim))
            objDB.AddParameter("LASF", Data.SqlDbType.Decimal, CDbl(txtLASF.Text.Trim))
            objDB.AddParameter("BUWidth", Data.SqlDbType.Decimal, CDbl(txtBUWidth.Text.Trim))
            objDB.AddParameter("BULength", Data.SqlDbType.Decimal, CDbl(txtBULength.Text.Trim))
            objDB.AddParameter("BUSF", Data.SqlDbType.Decimal, CDbl(txtBUSF.Text.Trim))
            If txtFloorLoad.Text <> String.Empty Then
                objDB.AddParameter("FloorLoad", Data.SqlDbType.NVarChar, txtFloorLoad.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("FloorLoad", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtSECMK.Text <> String.Empty Then
                objDB.AddParameter("SECMK", Data.SqlDbType.NVarChar, txtSECMK.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("SECMK", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtCeiling.Text <> String.Empty Then
                objDB.AddParameter("Ceiling", Data.SqlDbType.NVarChar, txtCeiling.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("Ceiling", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtTerrain.Text <> String.Empty Then
                objDB.AddParameter("Terrain", Data.SqlDbType.NVarChar, txtTerrain.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("Terrain", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtDistrict.Text <> String.Empty Then
                objDB.AddParameter("District", Data.SqlDbType.NVarChar, txtDistrict.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("District", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLot.Text <> String.Empty Then
                objDB.AddParameter("Lot", Data.SqlDbType.NVarChar, txtLot.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("Lot", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtPhase.Text <> String.Empty Then
                objDB.AddParameter("Phase", Data.SqlDbType.NVarChar, txtPhase.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("Phase", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            objDB.AddParameter("Furnished", Data.SqlDbType.TinyInt, CInt(ddlFurnished.SelectedValue))
            If txtFurnished.Text <> "Remark" Then
                objDB.AddParameter("FurnishedRemark", Data.SqlDbType.NVarChar, txtFurnished.Text.Trim)
            Else
                objDB.AddParameter("FurnishedRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            objDB.AddParameter("Renovated", Data.SqlDbType.TinyInt, CInt(ddlRenovated.SelectedValue))
            If txtRenovated.Text <> "Remark" Then
                objDB.AddParameter("RenovatedRemark", Data.SqlDbType.NVarChar, txtRenovated.Text.Trim)
            Else
                objDB.AddParameter("RenovatedRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtDeveloper.Text <> String.Empty Then
                objDB.AddParameter("Developer", Data.SqlDbType.NVarChar, txtDeveloper.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("Developer", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtName.Text <> String.Empty Then
                objDB.AddParameter("OwnerName", Data.SqlDbType.NVarChar, txtName.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerName", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtMobile.Text <> String.Empty Then
                objDB.AddParameter("OwnerMobile", Data.SqlDbType.NVarChar, txtMobile.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtPhone.Text <> String.Empty Then
                objDB.AddParameter("OwnerPhone", Data.SqlDbType.NVarChar, txtPhone.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtFax.Text <> String.Empty Then
                objDB.AddParameter("OwnerFax", Data.SqlDbType.NVarChar, txtFax.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerFax", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtEmail.Text <> String.Empty Then
                objDB.AddParameter("OwnerEmail", Data.SqlDbType.NVarChar, txtEmail.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtAddress.Text <> String.Empty Then
                objDB.AddParameter("OwnerAddress", Data.SqlDbType.NVarChar, txtAddress.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("OwnerAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordName.Text <> String.Empty Then
                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, txtLandlordName.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordMobile.Text <> String.Empty Then
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordPhone.Text <> String.Empty Then
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordFax.Text <> String.Empty Then
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordEmail.Text <> String.Empty Then
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordAddress.Text <> String.Empty Then
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.Trim.ToUpper)
            Else
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If chkReferLister.Checked Then
                objDB.AddParameter("ReferLister", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("ReferLister", Data.SqlDbType.TinyInt, 0)
            End If
            If chkLandlordReferLister.Checked Then
                objDB.AddParameter("ReferLandlordLister", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("ReferLandlordLister", Data.SqlDbType.TinyInt, 0)
            End If
            objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
            objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, DBNull.Value)

            objDB.AddParameter("CPPlanNo", Data.SqlDbType.NVarChar, txtCPPlanNo.Text.Trim.ToUpper)
            objDB.AddParameter("Floor", Data.SqlDbType.NVarChar, txtFloor.Text.Trim.ToUpper)
            objDB.AddParameter("CompanyName", Data.SqlDbType.NVarChar, txtCompanyName.Text.Trim.ToUpper)
            objDB.AddParameter("ViewContact", Data.SqlDbType.NVarChar, txtViewingContact.Text.Trim.ToUpper)
            objDB.AddParameter("OtherContact", Data.SqlDbType.NVarChar, txtOtherContact.Text.Trim.ToUpper)

            objDB.AddParameter("LandlordCompanyName", Data.SqlDbType.NVarChar, txtLandlordCompanyName.Text.Trim.ToUpper)
            objDB.AddParameter("LandlordViewContact", Data.SqlDbType.NVarChar, txtLandlordViewingContact.Text.Trim.ToUpper)
            objDB.AddParameter("LandlordOtherContact", Data.SqlDbType.NVarChar, txtLandlordOtherContact.Text.Trim.ToUpper)
            objDB.AddParameter("TitleNo", Data.SqlDbType.NVarChar, txtTitleNo.Text.Trim.ToUpper)

            If lblhidPropertyId.Text = "" Then 'New property
                objDB.dbVariable.SQLString = "INSERT INTO AW_Property " &
              "(PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, RTransactionId, STransactionId, SRAmt, " &
              "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " &
              "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " &
              "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " &
              "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " &
              "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " &
              "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " &
              "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " &
              "AuthorizeSaleRent, Remark, CommissionRemark,Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " &
              "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " &
              "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " &
              "OwnerAddress, ReferLister, RListStatus, SListStatus, RRelistStatus, SRelistStatus, CreateDate, StatusDelete, UpdateDate, UpdateWho, " &
              "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister, CPPlanNo, Floor, CompanyName, ViewContact, OtherContact, " &
              "LandlordCompanyName, LandlordViewContact, LandlordOtherContact, TitleNo, " &
              "SaleView, RentView, SaleGST, RentGST, SaleRemark, RentRemark, Latitude, Longitude, AgentFeedback,AgentFeedbackRent," &
              "SCreateDate,RCreateDate) " &
              "VALUES (@PropertyId, @RoadId, @ProjectId, @PropertyTypeID, @UnitNumber, @ListType, @RTransactionId, @STransactionId, @SRAmt, " &
              "@SRPSF, @SRAskAmt, @SRAskPSF, @SRCreateDate, @SRYes, @SCAmt, @SCPSF, @SCAskAmt, @SCAskPSF, @SCCreateDate, @SCYes, @SLAmt, " &
              "@SLPSF, @SLASkAmt, @SLAskPSF, @SLCreateDate, @SLYes, @SIAmt, @SIPSF, @SIAskAmt, @SIAskPSF, @SICreateDate, @SIYes, @RRAmt, " &
              "@RRPSF, @RRASkAmt, @RRAskPSF, @RRCreateDate, @RRYes, @RCAmt, @RCPSF, @RCASkAmt, @RCAskPSF, @RCCreateDate, @RCYes, @RLAmt, " &
              "@RLPSF, @RLAskAmt, @RLAskPSF, @RLCreateDate, @RLYes, @RIAmt, @RIPSF, @RIASkAmt, @RIAskPSF, @RICreateDate, @RIYes, " &
              "@SListerId, @RListerId, @KeyInOffice, @ProjectRemark, @PropertyDesc, @SignboardStatus, @SignboardWhere, @SignboardWhen, " &
              "@SurveySheet, @QuitRent, @AssessmentBill, @PendingStatus, @PendingWho, @PendingWhen, @PendingWhy, @Tenure, @ListHoldExpired, " &
              "@Access, @AccessRemark, @Condition, @ConditionRemark, @Facing, @Zoning, @ZoningRemark, @Room, @Bathroom, @BestBuy, @ExclusiveStatus, @ExclusiveWho, @ExclusiveWhen, @ExclusiveEndDate, " &
              "@AuthorizeSaleRent, @Remark, @CommissionRemark, @Production1, @Production2, @Production3, @Admin1, @Admin2, @Admin3, @LAWidth, @LALength, " &
              "@LASF, @BUWidth, @BULength, @BUSF, @FloorLoad, @SECMK, @Ceiling, @Terrain, @District, @Lot, @Phase, @Furnished, @FurnishedRemark, " &
              "@Renovated, @RenovatedRemark, @Developer, @OwnerName, @OwnerMobile, @OwnerPhone, @OwnerFax, @OwnerEmail, " &
              "@OwnerAddress, @ReferLister, @RListStatus, @SListStatus, @RRelistStatus, @SRelistStatus, @CreateDate, @StatusDelete, @UpdateDate, @UpdateWho, " &
              "@LandlordName, @LandlordMobile, @LandlordPhone, @LandlordFax, @LandlordEmail, @LandlordAddress, @ReferLandlordLister, @CPPlanNo, @Floor, @CompanyName, @ViewContact, @OtherContact, " &
              "@LandlordCompanyName, @LandlordViewContact, @LandlordOtherContact, @TitleNo," &
              "@SaleView, @RentView, @SaleGST, @RentGST,@SaleRemark, @RentRemark, @Latitude, @Longitude, @AgentFeedback, @AgentFeedbackRent," &
              "@SCreateDate,@RCreateDate)"
                'edited by minginn @ 2/4/2011 to fix the problem cannot go to addphoto page as the property id was passing using lblhidpropertyId field
                'Dim propertyid As Guid = Guid.NewGuid
                lblhidPropertyId.Text = Guid.NewGuid.ToString
                'objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, propertyid)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidPropertyId.Text))
                objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
                If lblhidProjectId.Text <> String.Empty Then
                    objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text))
                Else
                    objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                End If
                objDB.AddParameter("UnitNumber", Data.SqlDbType.NVarChar, txtUnitNumber.Text.ToUpper)
                objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, CInt(ddlListType.SelectedValue))
                If ddlListType.SelectedValue = "3" Then  '--Sale & Rent
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, Now())
                ElseIf ddlListType.SelectedValue = "2" Then  '--Rent
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                Else '--Sale
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.ExecuteQuery(False)

                'InsertRem_Old(lblhidPropertyId.Text, 'objDBLocal)
                InsertUpdateContactOwner(objDB)
                InsertUpdateContactLandlord(objDB)
                objDB.DbTransCommit()
                'objDBLocal.DbTransCommit()
            Else    'Update / Relist
                'Update
                Dim strCreateDate As String
                If lblhidCreateDate.Text <> "" Then
                    strCreateDate = ""
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidStaffId.Text))
                Else
                    strCreateDate = " CreateDate=@CreateDate, "
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                End If

                Dim sqlUpdateStr As String
                Dim teststr = lblhidListType.Text
                Dim sqlSCreate As String = ""
                Dim sqlRCreate As String = ""

                If lblhidListType.Text = "3" Then  '--Sale & Rent 'Edited by tanchinteong @26112012, use lblhidListType instead of ddlListType
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, 0)

                    If lblhidSCreateDate.Text = "" Then
                        objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                        sqlSCreate = ",SCreateDate=@ScreateDate "
                    Else
                        'do nothing
                    End If

                    If lblhidRCreateDate.Text = "" Then
                        objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                        sqlRCreate = ",RCreateDate=@RCreateDate "
                    Else
                        'do nothing
                    End If
                    sqlUpdateStr = "SRelistStatus=@SRelistStatus,RRelistStatus=@RRelistStatus " & sqlSCreate & sqlRCreate

                ElseIf lblhidListType.Text = "2" Then  '--Rent
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)   'added but not used for update, used in history logging(InsertRem_Old(lblhidPropertyId.Text.Trim, objDB)).
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, 0) 'Edited by tanchinteong @26112012
                    If lblhidRCreateDate.Text = "" Then
                        objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                        sqlRCreate = ",RCreateDate=@RCreateDate "
                    Else
                        'do nothing
                    End If
                    sqlUpdateStr = "RRelistStatus=@RRelistStatus " & sqlRCreate
                Else '--Sale
                    objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)   'added but not used for update, used in history logging(InsertRem_Old(lblhidPropertyId.Text.Trim, objDB)).

                    If lblhidSCreateDate.Text = "" Then
                        objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, Now())   'Edited by tanchinteong @26112012
                        sqlSCreate = ",SCreateDate=@ScreateDate "
                    Else
                        'do nothing
                    End If

                    sqlUpdateStr = "SRelistStatus=@SRelistStatus " & sqlSCreate
                End If

                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidPropertyId.Text.Trim))
                objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, CInt(lblhidListType.Text))

                objDB.dbVariable.SQLString = "UPDATE AW_Property SET " &
                                               "PropertyTypeId=@PropertyTypeId, ListType=@ListType, SRAmt=@SRAmt, SRPSF=@SRPSF, SRAskAmt=@SRAskAmt, SRAskPSF=@SRAskPSF, " &
                                               "SRCreateDate=@SRCreateDate, SRYes=@SRYes, SCAmt=@SCAmt, SCPSF=@SCPSF, SCAskAmt=@SCAskAmt, SCAskPSF=@SCAskPSF, " &
                                               "SCCreateDate=@SCCreateDate, SCYes=@SCYes, SLAmt=@SLAmt, SLPSF=@SLPSF, SLAskAmt=@SLAskAmt, SLAskPSF=@SLAskPSF, " &
                                               "SLCreateDate=@SLCreateDate, SLYes=@SLYes, SIAmt=@SIAmt, SIPSF=@SIPSF, SIASkAmt=@SIAskAmt, SIAskPSF=@SIAskPSF, " &
                                               "SICreateDate=@SICreateDate, SIYes=@SIYes, RRAmt=@RRAmt, RRPSF=@RRPSF, RRAskAmt=@RRAskAmt, RRAskPSF=@RRAskPSF, " &
                                               "RRCreateDate=@RRCreateDate, RRYes=@RRYes, RCAmt=@RCAmt, RCPSF=@RCPSF, RCAskAmt=@RCAskAmt, RCAskPSF=@RCAskPSF, " &
                                               "RCCreateDate=@RCCreateDate, RCYes=@RCYes, RLAmt=@RLAmt, RLPSF=@RLPSF, RLAskAmt=@RLAskAmt, RLAskPSF=@RLAskPSF, " &
                                               "RLCreateDate=@RLCreateDate, RLYes=@RLYes, RIAmt=@RIAmt, RIPSF=@RIPSF, RIAskAmt=@RIAskAmt, RIAskPSF=@RIAskPSF, " &
                                               "RICreateDate=@RICreateDate, RIYes=@RIYes, SListerId=@SListerId, RListerId=@RListerId, KeyInOffice=@KeyInOffice, " &
                                               "ProjectRemark=@ProjectRemark, PropertyDesc=@PropertyDesc, SignboardStatus=@SignboardStatus, SignboardWhere=@SignboardWhere, " &
                                               "SignboardWhen=@SignboardWhen, SurveySheet=@SurveySheet, QuitRent=@QuitRent, AssessmentBill=@AssessmentBill, " &
                                               "RentPendingStatus=@RentPendingStatus, RentPendingWho=@RentPendingWho, RentPendingWhen=@RentPendingWhen, RentPendingWhy=@RentPendingWhy," &
                                               "PendingStatus=@PendingStatus, PendingWho=@PendingWho, PendingWhen=@PendingWhen, PendingWhy=@PendingWhy, Tenure=@Tenure, " &
                                               "ListholdExpired=@ListholdExpired, Access=@Access, AccessRemark=@AccessRemark, Condition=@Condition, ConditionRemark=@ConditionRemark, " &
                                               "Facing=@Facing, Zoning=@Zoning, ZoningRemark=@ZoningRemark, Room=@Room, " &
                                               "Bathroom=@Bathroom, BestBuy=@BestBuy, ExclusiveStatus=@ExclusiveStatus, ExclusiveWho=@ExclusiveWho, ExclusiveWhen=@ExclusiveWhen, " &
                                               "ExclusiveEndDate=@ExclusiveEndDate, AuthorizeSaleRent=@AuthorizeSaleRent, Remark=@Remark,CommissionRemark=@CommissionRemark, Production1=@Production1, " &
                                               "Production2=@Production2, Production3=@Production3, Admin1=@Admin1, Admin2=@Admin2, Admin3=@Admin3, LAWidth=@LAWidth, " &
                                               "LALength=@LALength, LASF=@LASF, BUWidth=@BUWidth, BULength=@BULength, BUSF=@BUSF, FloorLoad=@FloorLoad, SECMK=@SECMK, " &
                                               "Ceiling=@Ceiling, Terrain=@Terrain, District=@District, Lot=@Lot, Phase=@Phase, Furnished=@Furnished, FurnishedRemark=@FurnishedRemark, " &
                                               "Renovated=@Renovated, RenovatedRemark=@RenovatedRemark, Developer=@Developer, OwnerName=@OwnerName, OwnerMobile=@OwnerMobile, " &
                                               "OwnerPhone=@OwnerPhone, OwnerFax=@OwnerFax, OwnerEmail=@OwnerEmail, OwnerAddress=@OwnerAddress, ReferLister=@ReferLister, " &
                                               "" & strCreateDate & "UpdateDate=@UpdateDate, UpdateWho=@UpdateWho, " &
                                               "LandlordName=@LandlordName, LandlordMobile=@LandlordMobile, LandlordPhone=@LandlordPhone, LandlordFax=@LandlordFax, " &
                                               "LandlordEmail=@LandlordEmail, LandlordAddress=@LandlordAddress, ReferLandlordLister=@ReferLandlordLister, " &
                                               "CPPlanNo=@CPPlanNo, Floor=@Floor, CompanyName=@CompanyName, ViewContact=@ViewContact, OtherContact=@OtherContact, " &
                                               "LandlordCompanyName=@LandlordCompanyName, LandlordViewContact=@LandlordViewContact, LandlordOtherContact=@LandlordOtherContact, TitleNo=@TitleNo,AgentFeedback=@AgentFeedback,AgentFeedbackRent=@AgentFeedbackRent," &
                                               "SaleView=@SaleView, RentView=@RentView, SaleGST=@SaleGST, RentGST=@RentGST,SaleRemark=@SaleRemark, RentRemark=@RentRemark, Latitude=@Latitude, Longitude=@Longitude, " &
                                               sqlUpdateStr & "WHERE PropertyId=@PropertyId"

                objDB.ExecuteQuery(False)
                'InsertRem_Old(lblhidPropertyId.Text.Trim, 'objDBLocal)
                InsertUpdateContactOwner(objDB)
                InsertUpdateContactLandlord(objDB)
                'objDBLocal.DbTransCommit()
                objDB.DbTransCommit()
            End If
            objDB.CloseConnection()
            'objDBLocal.CloseConnection()
            'Session.Add("entry", lblAddress.Text.Trim)
            'Response.Redirect("Propertylist.aspx", False)
            'Added by : Daniel Lee
            'Purpose : To Pass the following action to Add Photo
            'Session.Add("PropertyID", lblhidPropertyId.Text.ToString)
            'Session.Add("Address", lblAddress.Text.Trim)
            'Session.Add("tp", lblhidListType.Text.Trim)
            'Response.Redirect("addPhoto.aspx", False)
            'once save. stop
            ' cater Web Page save
            divSuccessful.Visible = True
            lblMsgSuccessful.Text = "Properrty Save!"
            udpMessage.Update()


        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
            'If 'objDBLocal.dbVariable.objConn.State = Data.ConnectionState.Open Then
            'objDBLocal.DbTransRollback()
            'objDBLocal.CloseConnection()
            'End If

            lblMsgError.Text = ex.Message & ex.InnerException.Message & " Please make sure all necessary fields are filled in properly."
            divError.Visible = True
            udpMessage.Update()
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "divError", "$get('" + divError.ClientID + "').style.display='block';", True)
        End Try

    End Sub


    Protected Sub btnPropertyTypeSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPropertyTypeSearch.Click
        GetrepPropertyType()
        mpePropertyTypeEntry.Show()
    End Sub

    Protected Sub repPropertyType_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repPropertyType.ItemCommand
        If e.CommandName.ToUpper = "SELECTITEM" Then
            txtPropertyType.Text = CType(repPropertyType.Items(e.CommandArgument).FindControl("lbtRepPropertyTypeEdit"), LinkButton).Text
            lblhidPropertyTypeId.Text = CType(repPropertyType.Items(e.CommandArgument).FindControl("lblRepPropertyTypeUID"), Label).Text
        End If
    End Sub

    Private Sub GetrepProject()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT Project,ProjectId FROM AW_Project WHERE StatusDelete = 0 AND Project like '%" & txtProjectName.Text.Trim & "%' AND RoadId = @RoadId ORDER BY Project"
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
        objDB.FillData(TempDT, "AW_Project", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        If TempDT.Rows.Count = 0 Then
            lblNoProjectFound.Text = "No Project Name Found."
        Else
            repProject.DataSource = TempDT
            repProject.DataBind()
            lblNoProjectFound.Text = String.Empty
        End If
    End Sub

    Private Sub GetrepRoad()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT Road,RoadId FROM AW_Road WHERE StatusDelete = 0 AND Road like '%" & txtRoadName.Text.Trim & "%' AND LocationId = @LocationId ORDER BY Road"
        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlLocation.SelectedValue))
        objDB.FillData(TempDT, "AW_Road", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        If TempDT.Rows.Count = 0 Then
            lblNoRoadFound.Text = "No Road Name Found."
        Else
            repRoad.DataSource = TempDT
            repRoad.DataBind()
            lblNoRoadFound.Text = String.Empty
        End If
    End Sub

    Private Sub GetrepPropertyType()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE StatusDelete = 0 AND Type like '%" & txtPropertyType.Text.Trim & "%' ORDER BY Type"
        objDB.FillData(TempDT, "AW_PropertyType", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        repPropertyType.DataSource = TempDT
        repPropertyType.DataBind()
    End Sub

    Private Sub GetrepLister()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT StaffId,Name FROM AW_Staff WHERE StatusDelete = 0 ORDER BY Name"
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        repListerList.DataSource = TempDT
        repListerList.DataBind()

    End Sub

    Private Sub GetddlCountry()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT CountryId,Country FROM AW_Country WHERE StatusDelete = 0 ORDER BY Country"
        objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

        With ddlCountry
            .DataSource = TempDT
            .DataTextField = "Country"
            .DataValueField = "CountryId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        ddlCountry.SelectedIndex = 1

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlState(ByVal strCountry As String)
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If strCountry = "" Then
            strCountry = Guid.Empty.ToString
        End If

        objDB.dbVariable.SQLString = "SELECT StateId,State FROM AW_State WHERE CountryId = @CountryId AND StatusDelete = 0 ORDER BY State"
        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(strCountry))
        objDB.FillData(TempDT, "State", Database.SQLCommandType.NormalString)

        With ddlState
            .DataSource = TempDT
            .DataTextField = "State"
            .DataValueField = "StateId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlLocation(ByVal strState As String)
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If strState = "" Then
            strState = Guid.Empty.ToString
        End If

        objDB.dbVariable.SQLString = "SELECT LocationId,Location FROM AW_Location WHERE StateId = @StateId AND StatusDelete = 0 ORDER BY Location"
        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(strState))
        objDB.FillData(TempDT, "Location", Database.SQLCommandType.NormalString)

        With ddlLocation
            .DataSource = TempDT
            .DataTextField = "Location"
            .DataValueField = "LocationId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        GetddlState(ddlCountry.SelectedValue)
    End Sub

    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        GetddlLocation(ddlState.SelectedValue)
    End Sub

    Protected Sub btnSListerList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSListerList.Click
        lblhidListerType.Text = "S"
        GetrepLister()
        mpeListerListEntry.Show()
    End Sub

    Protected Sub btnRoadNameSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRoadNameSearch.Click
        If ddlLocation.SelectedValue.ToString = "" Then
            lblMsgError.Text = "Please select a location"
            divError.Visible = True
        Else
            GetrepRoad()
            mpeRoadEntry.Show()
        End If

    End Sub

    Protected Sub repRoad_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repRoad.ItemCommand
        If e.CommandName.ToUpper = "SELECTITEM" Then
            lblUnitNumber.Text = String.Empty
            txtRoadName.Text = CType(repRoad.Items(e.CommandArgument).FindControl("lbtRepRoadEdit"), LinkButton).Text
            lblhidRoadId.Text = CType(repRoad.Items(e.CommandArgument).FindControl("lblRepRoadID"), Label).Text
            Dim tempdt As Data.DataTable
            tempdt = getUnitFormat()
            If tempdt.Rows.Count >= 1 Then
                For i As Integer = 0 To tempdt.Rows.Count - 1
                    If lblUnitNumber.Text = "" Then
                        lblUnitNumber.Text = tempdt.Rows(i).Item("UnitFormat")
                    Else
                        lblUnitNumber.Text += ", " & tempdt.Rows(i).Item("UnitFormat")
                    End If
                Next
            End If
        End If
    End Sub

    Protected Sub btnProjectNameSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProjectNameSearch.Click
        If lblhidRoadId.Text = "" Then
            lblMsgError.Text = "Please select a ROAD"
            divError.Visible = True
        Else
            GetrepProject()
            mpeProjectEntry.Show()
        End If
    End Sub

    Protected Sub repProject_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repProject.ItemCommand
        If e.CommandName.ToUpper = "SELECTITEM" Then
            lblUnitNumber.Text = String.Empty
            txtProjectName.Text = CType(repProject.Items(e.CommandArgument).FindControl("lbtRepProjectEdit"), LinkButton).Text
            lblhidProjectId.Text = CType(repProject.Items(e.CommandArgument).FindControl("lblRepProjectId"), Label).Text
            Dim tempdt As Data.DataTable
            tempdt = getUnitFormat()
            If tempdt.Rows.Count >= 1 Then
                For i As Integer = 0 To tempdt.Rows.Count - 1
                    If lblUnitNumber.Text = "" Then
                        lblUnitNumber.Text = tempdt.Rows(i).Item("UnitFormat")
                    Else
                        lblUnitNumber.Text += ", " & tempdt.Rows(i).Item("UnitFormat")
                    End If
                Next
            End If
        End If
    End Sub

    Private Function getUnitFormat() As Data.DataTable

        Dim ProjectFilter As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        If txtProjectName.Text = String.Empty Then
            ProjectFilter = " AND ProjectId IS NULL"
        Else
            ProjectFilter = " AND ProjectId = @ProjectId"
            objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text.Trim))
        End If

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT UnitId, UnitFormat, LEN(UnitFormat) as UnitLength FROM aw_unit WHERE StatusDelete=0 AND CountryId=@CountryId AND StateId=@StateId " &
                                    "AND LocationId=@LocationId AND RoadId=@RoadId" & ProjectFilter
        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlCountry.SelectedValue))
        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlState.SelectedValue))
        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlLocation.SelectedValue))
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text.Trim))
        objDB.FillData(TempDT, "AW_UnitNumberFormat", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        Return TempDT

    End Function

    Private Function checkUnitFormat(ByVal unitNumber As String) As Boolean
        'Edited to not compare unit number format if unit number format not setup
        'if multiple unit format, check multiple unit length
        Dim tempDT As Data.DataTable
        Dim DBUnitFormat As String
        Dim blnUnitFormat As Boolean = False

        tempDT = getUnitFormat()
        If tempDT.Rows.Count > 0 Then
            tempDT.TableName = "tblUnitFormat"
            Dim tempView As New Data.DataView(tempDT)
            tempView.RowFilter = "UnitLength = " & unitNumber.Length

            For n As Integer = 0 To tempView.Count - 1
                DBUnitFormat = tempView(n).Item("UnitFormat").ToString()
                For w As Integer = 0 To DBUnitFormat.Length - 1
                    If Char.IsLetter(DBUnitFormat.Substring(w, 1)) = True Then
                        If Char.IsLetter(unitNumber.Substring(w, 1)) = True Then
                            blnUnitFormat = True
                        Else
                            blnUnitFormat = False
                            Exit For
                        End If
                    ElseIf Char.IsNumber(DBUnitFormat.Substring(w, 1)) = True Then
                        If Char.IsNumber(unitNumber.Substring(w, 1)) = True Then
                            blnUnitFormat = True
                        Else
                            blnUnitFormat = False
                            Exit For
                        End If
                    Else
                        If unitNumber.Substring(w, 1) = DBUnitFormat.Substring(w, 1) Then
                            blnUnitFormat = True
                        Else
                            blnUnitFormat = False
                            Exit For
                        End If
                    End If
                Next   '--to determine the format of character
                If blnUnitFormat Then
                    Return blnUnitFormat
                End If
            Next   '--to loop around the length of the string
            Return blnUnitFormat
        Else
            '--if no unit number format
            '--Check not consist dashed, then true
            If InStr(unitNumber, "-") > 0 Then
                blnUnitFormat = False
            Else
                blnUnitFormat = True
            End If
            Return blnUnitFormat
        End If
    End Function

    Private Function CheckUnitExistence(ByVal unitNumber As String) As Boolean
        Dim ProjectFilter As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        If txtProjectName.Text = String.Empty Then
            ProjectFilter = " AND ProjectId IS NULL"
        Else
            ProjectFilter = " AND ProjectId = @ProjectId"
            objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text.Trim))
        End If

        objDB.OpenConnection()

        'edit by tanchinteong 20140109
        'remove project if is not boss & admin
        If lblhidStaffType.Text = "1" Or lblhidStaffType.Text = "5" Then

        Else
            ProjectFilter = ""
        End If

        'edited by minginn @23/5/2011 - to only allow to list a property when the RelistStatus=NULL
        objDB.dbVariable.SQLString = "SELECT PropertyId, UnitNumber, ListType, RRelistStatus, SRelistStatus FROM aw_property WHERE RoadId=@RoadId AND UnitNumber=@UnitNumber " &
                                    "AND StatusDelete=0 " & ProjectFilter  '*** edit by tanchinteong 20131003 -remove project criteria comparison
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
        objDB.AddParameter("UnitNumber", Data.SqlDbType.NVarChar, unitNumber.ToUpper)
        objDB.FillData(TempDT, "AW_UnitNumber", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        'if current is rent and selected sale - pass
        'if current is sale and selected sale, rent - fail
        'if current is SR - fail
        'Edited by minginn @ 20/4/2011 
        'Make changes to accept Sale if only rent created, accept rent if only sales created
        If TempDT.Rows.Count > 0 Then
            If TempDT.Rows(0).Item("ListType").ToString = "2" Then  '--Rent
                If ddlListType.SelectedValue = "1" Then  '--if selected is sale
                    If TempDT.Rows(0).Item("SRelistStatus").ToString = "" Then  '--if sale reliststatus is null, pass
                        lblhidISEFP.Text = "1"
                        lblhidListType.Text = "1"
                        'ddlListType.SelectedValue = "3"
                        lblhidPropertyId.Text = TempDT.Rows(0).Item("PropertyId").ToString
                        Return True
                    Else
                        divError.Visible = True
                        lblMsgError.Text = "The property has already been listed for SALE, please relist before you list agian."
                        Return False
                    End If
                Else
                    divError.Visible = True
                    lblMsgError.Text = "The property has already been listed for RENT, please check the system."
                    Return False
                End If
            ElseIf TempDT.Rows(0).Item("ListType").ToString = "1" Then      '--To accept also rent if sale already created
                If ddlListType.SelectedValue = "2" Then  '--if selected is rent
                    If TempDT.Rows(0).Item("RRelistStatus").ToString = "" Then  '--if rent reliststatus is null, pass
                        If TempDT.Rows(0).Item("SRelistStatus").ToString = "2" Then
                            divError.Visible = True
                            lblMsgError.Text = "Please Relist the property before proceed"
                            Return False
                        Else
                            lblhidISEFP.Text = "1"
                            lblhidListType.Text = "2"
                            'ddlListType.SelectedValue = "3"
                            lblhidPropertyId.Text = TempDT.Rows(0).Item("PropertyId").ToString
                            Return True
                        End If
                    Else
                        divError.Visible = True
                        lblMsgError.Text = "The property has already been listed for RENT"
                        Return False
                    End If
                Else
                    divError.Visible = True
                    lblMsgError.Text = "The property has already been listed for SALE"
                    Return False
                End If
            ElseIf TempDT.Rows(0).Item("ListType").ToString = "3" Then  '--if already created for both then error
                divError.Visible = True
                lblMsgError.Text = "The property has already been listed"
                Return False
            Else
                lblhidListType.Text = ddlListType.SelectedValue
                lblhidISEFP.Text = "1"
                lblhidPropertyId.Text = TempDT.Rows(0).Item("PropertyId").ToString
                Return True
                '    'New entry for existing property - Will do it when related to transaction
                '    lblhidISEFP.Text = "1"
                '    lblhidPropertyId.Text = TempDT.Rows(0).Item("PropertyId").ToString
            End If
        Else
            lblhidListType.Text = ddlListType.SelectedValue
            Return True
        End If
    End Function

    Protected Sub btnSubmitPreEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmitPreEntry.Click

        If Session("DirectFromPropertyView") Is Nothing Then
            Session.Add("DirectFromPropertyView", "NO")
        Else
            Session("DirectFromPropertyView") = "NO"
        End If

        divError.Visible = False

        If ValidateSubmission() Then
            'check unit number existence
            'check unit number format
            If CheckUnitExistence(txtUnitNumber.Text.Trim) Then
                If checkUnitFormat(txtUnitNumber.Text.Trim) Then
                    pnlPreEntry.Visible = False
                    pnlEntry.Visible = True
                    If ddlListType.SelectedValue = "3" Then  '--Sale & Rent
                        If ProjectCB.Checked = False Then
                            RR.Visible = True
                            RC.Visible = True
                            RL.Visible = True
                            RI.Visible = True
                            SR.Visible = True
                            SC.Visible = True
                            SL.Visible = True
                            SI.Visible = True
                        Else
                            RR.Visible = False
                            RC.Visible = False
                            RL.Visible = True
                            RI.Visible = False
                            SR.Visible = False
                            SC.Visible = False
                            SL.Visible = True
                            SI.Visible = False
                        End If
                        RLister.Visible = True
                        SLister.Visible = True
                        RTitle.Visible = True
                        sTitle.Visible = True
                        rfvtxtRLister.Enabled = True
                        rfvtxtSLister.Enabled = True
                        divContentLandlord.Visible = True
                        divContentOwner.Visible = True
                    ElseIf ddlListType.SelectedValue = "2" Then  '--Rent
                        If ProjectCB.Checked = False Then
                            RR.Visible = True
                            RC.Visible = True
                            RL.Visible = True
                            RI.Visible = True
                        Else
                            RR.Visible = False
                            RC.Visible = False
                            RL.Visible = True
                            RI.Visible = False
                        End If

                        SR.Visible = False
                        SC.Visible = False
                        SL.Visible = False
                        SI.Visible = False
                        RLister.Visible = True
                        SLister.Visible = False
                        RTitle.Visible = True
                        sTitle.Visible = False
                        rfvtxtRLister.Enabled = True
                        rfvtxtSLister.Enabled = False
                        divContentLandlord.Visible = True
                        divContentOwner.Visible = False
                    ElseIf ddlListType.SelectedValue = "1" Then '--Sale
                        RR.Visible = False
                        RC.Visible = False
                        RL.Visible = False
                        RI.Visible = False
                        If ProjectCB.Checked = False Then
                            SR.Visible = True
                            SC.Visible = True
                            SL.Visible = True
                            SI.Visible = True
                        Else
                            SR.Visible = False
                            SC.Visible = False
                            SI.Visible = False
                            SL.Visible = True
                        End If

                        RLister.Visible = False
                        SLister.Visible = True
                        RTitle.Visible = False
                        sTitle.Visible = True
                        rfvtxtRLister.Enabled = False
                        rfvtxtSLister.Enabled = True
                        divContentLandlord.Visible = False
                        divContentOwner.Visible = True
                    End If
                    If lblhidStaffType.Text = "2" Then  '--1-Boss, 2-Ren, 3-Admin
                        If ddlListType.SelectedValue = "1" Then
                            lblSLister.Text = getName(lblhidStaffId.Text)
                            lblhidSListerId.Text = lblhidStaffId.Text
                            txtSLister.Text = lblSLister.Text
                        ElseIf ddlListType.SelectedValue = "2" Then
                            lblRLister.Text = getName(lblhidStaffId.Text)
                            lblhidRListerId.Text = lblhidStaffId.Text
                            txtRLister.Text = lblRLister.Text
                        ElseIf ddlListType.SelectedValue = "3" Then
                            lblSLister.Text = getName(lblhidStaffId.Text)
                            lblhidSListerId.Text = lblhidStaffId.Text
                            txtSLister.Text = lblSLister.Text
                            lblRLister.Text = getName(lblhidStaffId.Text)
                            lblhidRListerId.Text = lblhidStaffId.Text
                            txtRLister.Text = lblRLister.Text
                        End If
                        btnSListerList.Visible = False
                        btnRListerList.Visible = False
                    End If
                    GetAddress()
                    GetProjectName()
                Else
                    divError.Visible = True
                    lblMsgError.Text = "Invalid unit number"
                End If
            End If
            If lblhidISEFP.Text = "1" Then
                LoadProperty(lblhidPropertyId.Text, lblhidListType.Text)
            End If
        Else
            Exit Sub
        End If
    End Sub

    Private Function ValidateSubmission() As Boolean
        Dim blnRoad, blnProject As Boolean

        If txtRoadName.Text <> String.Empty Then
            If lblhidRoadId.Text = String.Empty Then
                blnRoad = False
                lblReqRoadName.Text = "*<br />Road Name Not Found"
            Else
                blnRoad = True
            End If
        Else
            blnRoad = True
        End If

        If txtProjectName.Text <> String.Empty Then
            If lblhidProjectId.Text = String.Empty Then
                blnProject = False
                lblReqProjectName.Text = "*<br />Project Name Not Found"
                lblReqProjectName.Visible = True
            Else
                blnProject = True
            End If
        Else
            blnProject = True
        End If

        If Not blnRoad Or Not blnProject Then
            Return False
        Else
            If (txtProjectName.Text = String.Empty And ProjectCB.Checked = False) Then
                lblReqProjectName.Text = "*<br />Project Name Is Required Or Tick Land"
                lblReqProjectName.Visible = True
                Return False
            End If
            Return True
        End If
    End Function

    Protected Sub repListerList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repListerList.ItemCommand
        If e.CommandName.ToUpper = "SELECTITEM" Then
            If lblhidListerType.Text = "R" Then
                lblRLister.Text = CType(repListerList.Items(e.CommandArgument).FindControl("lbtrepListerListEdit"), LinkButton).Text
                txtRLister.Text = lblRLister.Text
                lblhidRListerId.Text = CType(repListerList.Items(e.CommandArgument).FindControl("lblRepListerListId"), Label).Text
            ElseIf lblhidListerType.Text = "S" Then
                lblSLister.Text = CType(repListerList.Items(e.CommandArgument).FindControl("lbtrepListerListEdit"), LinkButton).Text
                txtSLister.Text = lblSLister.Text
                lblhidSListerId.Text = CType(repListerList.Items(e.CommandArgument).FindControl("lblRepListerListId"), Label).Text
            End If
        End If
        Page.ClientScript.RegisterStartupScript(Me.[GetType](), "anchor", "location.hash = '#Lister';", True)
    End Sub

    Protected Sub btnRListerList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRListerList.Click
        lblhidListerType.Text = "R"
        GetrepLister()
        mpeListerListEntry.Show()
    End Sub

    'Protected Sub chkPendingStatus_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkPendingStatus.CheckedChanged
    '    If chkPendingStatus.Checked Then
    '        txtPendingWhen.Visible = True
    '        txtPendingWho.Visible = True
    '        txtPendingWhy.Visible = True
    '    Else
    '        SetTextBoxHints(txtPendingWho, "Who")
    '        SetTextBoxHints(txtPendingWhen, "Date")
    '        SetTextBoxHints(txtPendingWhy, "Why")
    '        txtPendingWhen.Visible = False
    '        txtPendingWho.Visible = False
    '        txtPendingWhy.Visible = False
    '    End If
    'End Sub

    'Protected Sub chkExclusiveStatus_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkExclusiveStatus.CheckedChanged
    '    If chkExclusiveStatus.Checked Then
    '        txtExclusiveWho.Visible = True
    '        txtExclusiveWhen.Visible = True
    '        txtExclusiveEndDate.Visible = True
    '    Else
    '        SetTextBoxHints(txtExclusiveWho, "Who")
    '        SetTextBoxHints(txtExclusiveWhen, "When")
    '        SetTextBoxHints(txtExclusiveEndDate, "End Date")
    '        txtExclusiveWho.Visible = False
    '        txtExclusiveWhen.Visible = False
    '        txtExclusiveEndDate.Visible = False
    '    End If
    'End Sub

    'Protected Sub ddlTenure_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTenure.SelectedIndexChanged
    '    If ddlTenure.SelectedValue = "2" Then  '--Listhold
    '        txtListholdExpired.Visible = True
    '    Else
    '        SetTextBoxHints(txtListholdExpired, "Listhold Expired")
    '        txtListholdExpired.Visible = False
    '    End If
    'End Sub

    'Protected Sub chkSignboard_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSignboard.CheckedChanged
    '    If chkSignboard.Checked Then
    '        txtSignboardDate.Visible = True
    '        txtSignboardWhere.Visible = True
    '    Else
    '        SetTextBoxHints(txtSignboardWhere, "Where")
    '        SetTextBoxHints(txtSignboardDate, "Date")
    '        txtSignboardDate.Visible = False
    '        txtSignboardWhere.Visible = False
    '    End If
    'End Sub

    'Protected Sub chkRC_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRC.CheckedChanged
    '    If chkRC.Checked Then
    '        rfvtxtRCAmt.Enabled = True
    '        rfvtxtRCPSF.Enabled = True
    '        rfvtxtRCAskAmt.Enabled = True
    '        rfvtxtRCAskPSF.Enabled = True
    '        rfvtxtRCCreateDate.Enabled = True
    '        lblRCRequired.Visible = True
    '    Else
    '        rfvtxtRCAmt.Enabled = False
    '        rfvtxtRCPSF.Enabled = False
    '        rfvtxtRCAskAmt.Enabled = False
    '        rfvtxtRCAskPSF.Enabled = False
    '        rfvtxtRCCreateDate.Enabled = False
    '        lblRCRequired.Visible = False
    '        txtRCAmt.Text = String.Empty
    '        txtRCPSF.Text = String.Empty
    '        txtRCAskAmt.Text = String.Empty
    '        txtRCAskPSF.Text = String.Empty
    '        txtRCCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkRR_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRR.CheckedChanged
    '    If chkRR.Checked Then
    '        rfvtxtRRAmt.Enabled = True
    '        rfvtxtRRPSF.Enabled = True
    '        rfvtxtRRAskAmt.Enabled = True
    '        rfvtxtRRAskPSF.Enabled = True
    '        rfvtxtRRCreateDate.Enabled = True
    '        lblRRRequired.Visible = True
    '    Else
    '        rfvtxtRRAmt.Enabled = False
    '        rfvtxtRRPSF.Enabled = False
    '        rfvtxtRRAskAmt.Enabled = False
    '        rfvtxtRRAskPSF.Enabled = False
    '        rfvtxtRRCreateDate.Enabled = False
    '        lblRRRequired.Visible = False
    '        txtRRAmt.Text = String.Empty
    '        txtRRPSF.Text = String.Empty
    '        txtRRAskAmt.Text = String.Empty
    '        txtRRAskPSF.Text = String.Empty
    '        txtRRCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkRI_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRI.CheckedChanged
    '    If chkRI.Checked Then
    '        rfvtxtRIAmt.Enabled = True
    '        rfvtxtRIPSF.Enabled = True
    '        rfvtxtRIAskAmt.Enabled = True
    '        rfvtxtRIAskPSF.Enabled = True
    '        rfvtxtRICreateDate.Enabled = True
    '        lblRIRequired.Visible = True
    '    Else
    '        rfvtxtRIAmt.Enabled = False
    '        rfvtxtRIPSF.Enabled = False
    '        rfvtxtRIAskAmt.Enabled = False
    '        rfvtxtRIAskPSF.Enabled = False
    '        rfvtxtRICreateDate.Enabled = False
    '        lblRIRequired.Visible = False
    '        txtRIAmt.Text = String.Empty
    '        txtRIPSF.Text = String.Empty
    '        txtRIAskAmt.Text = String.Empty
    '        txtRIAskPSF.Text = String.Empty
    '        txtRICreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkRL_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRL.CheckedChanged
    '    If chkRL.Checked Then
    '        rfvtxtRLAmt.Enabled = True
    '        rfvtxtRLPSF.Enabled = True
    '        rfvtxtRLAskAmt.Enabled = True
    '        rfvtxtRLAskPSF.Enabled = True
    '        rfvtxtRLCreateDate.Enabled = True
    '        lblRLRequired.Visible = True
    '    Else
    '        rfvtxtRLAmt.Enabled = False
    '        rfvtxtRLPSF.Enabled = False
    '        rfvtxtRLAskAmt.Enabled = False
    '        rfvtxtRLAskPSF.Enabled = False
    '        rfvtxtRLCreateDate.Enabled = False
    '        lblRLRequired.Visible = False
    '        txtRLAmt.Text = String.Empty
    '        txtRLPSF.Text = String.Empty
    '        txtRLAskAmt.Text = String.Empty
    '        txtRLAskPSF.Text = String.Empty
    '        txtRLCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkSC_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSC.CheckedChanged
    '    If chkSC.Checked Then
    '        rfvtxtSCAmt.Enabled = True
    '        rfvtxtSCPSF.Enabled = True
    '        rfvtxtSCAskAmt.Enabled = True
    '        rfvtxtSCAskPSF.Enabled = True
    '        rfvtxtSCCreateDate.Enabled = True
    '        lblSCRequired.Visible = True
    '    Else
    '        rfvtxtSCAmt.Enabled = False
    '        rfvtxtSCPSF.Enabled = False
    '        rfvtxtSCAskAmt.Enabled = False
    '        rfvtxtSCAskPSF.Enabled = False
    '        rfvtxtSCCreateDate.Enabled = False
    '        lblSCRequired.Visible = False
    '        txtSCAmt.Text = String.Empty
    '        txtSCPSF.Text = String.Empty
    '        txtSCAskAmt.Text = String.Empty
    '        txtSCAskPSF.Text = String.Empty
    '        txtSCCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkSR_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSR.CheckedChanged
    '    If chkSR.Checked Then
    '        rfvtxtSRAmt.Enabled = True
    '        rfvtxtSRPSF.Enabled = True
    '        rfvtxtSRAskAmt.Enabled = True
    '        rfvtxtSRAskPSF.Enabled = True
    '        rfvtxtSRCreateDate.Enabled = True
    '        lblSRRequired.Visible = True
    '    Else
    '        rfvtxtSRAmt.Enabled = False
    '        rfvtxtSRPSF.Enabled = False
    '        rfvtxtSRAskAmt.Enabled = False
    '        rfvtxtSRAskPSF.Enabled = False
    '        rfvtxtSRCreateDate.Enabled = False
    '        lblSRRequired.Visible = False
    '        txtSRAmt.Text = String.Empty
    '        txtSRPSF.Text = String.Empty
    '        txtSRAskAmt.Text = String.Empty
    '        txtSRAskPSF.Text = String.Empty
    '        txtSRCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkSL_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSL.CheckedChanged
    '    If chkSL.Checked Then
    '        rfvtxtSLAmt.Enabled = True
    '        rfvtxtSLPSF.Enabled = True
    '        rfvtxtSLAskAmt.Enabled = True
    '        rfvtxtSLAskPSF.Enabled = True
    '        rfvtxtSLCreateDate.Enabled = True
    '        lblSLRequired.Visible = True
    '    Else
    '        rfvtxtSLAmt.Enabled = False
    '        rfvtxtSLPSF.Enabled = False
    '        rfvtxtSLAskAmt.Enabled = False
    '        rfvtxtSLAskPSF.Enabled = False
    '        rfvtxtSLCreateDate.Enabled = False
    '        lblSLRequired.Visible = False
    '        txtSLAmt.Text = String.Empty
    '        txtSLPSF.Text = String.Empty
    '        txtSLAskAmt.Text = String.Empty
    '        txtSLAskPSF.Text = String.Empty
    '        txtSLCreateDate.Text = String.Empty
    '    End If
    'End Sub

    'Protected Sub chkSI_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSI.CheckedChanged
    '    If chkSI.Checked Then
    '        rfvtxtSIAmt.Enabled = True
    '        rfvtxtSIPSF.Enabled = True
    '        rfvtxtSIAskAmt.Enabled = True
    '        rfvtxtSIAskPSF.Enabled = True
    '        rfvtxtSICreateDate.Enabled = True
    '        lblSIRequired.Visible = True
    '    Else
    '        rfvtxtSIAmt.Enabled = False
    '        rfvtxtSIPSF.Enabled = False
    '        rfvtxtSIAskAmt.Enabled = False
    '        rfvtxtSIAskPSF.Enabled = False
    '        rfvtxtSICreateDate.Enabled = False
    '        lblSIRequired.Visible = False
    '        txtSIAmt.Text = String.Empty
    '        txtSIPSF.Text = String.Empty
    '        txtSIAskAmt.Text = String.Empty
    '        txtSIAskPSF.Text = String.Empty
    '        txtSICreateDate.Text = String.Empty
    '    End If
    'End Sub

    Private Function getName(ByVal StaffId As String) As String
        Dim StaffName As String = String.Empty
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        'objDB.dbVariable.SQLString = "Select Name FROM AW_Staff WHERE StaffId = @StaffId AND StatusDelete = 0"
        objDB.dbVariable.SQLString = "Select Name FROM AW_Staff WHERE StaffId = @StaffId"
        objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(StaffId))

        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        If TempDT.Rows.Count > 0 Then
            StaffName = TempDT.Rows(0).Item("Name").ToString
        End If

        Return StaffName
    End Function

    Private Sub GetAddress()
        'Unit Number + , + Road Name + , + Location + , + State + , + Country
        Dim roadName, location, state, country, address As String
        Dim LocationID, StateID, CountryID As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "Select Road, LocationId FROM AW_Road WHERE RoadId = @RoadId"
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))

        objDB.FillData(TempDT, "AW_Road", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            roadName = TempDT.Rows(0).Item("Road").ToString
            LocationID = TempDT.Rows(0).Item("LocationId").ToString
        End If

        objDB.ClearParameter()
        TempDT = New Data.DataTable

        objDB.dbVariable.SQLString = "Select Location, StateId FROM AW_Location WHERE LocationId = @LocationId"
        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, New Guid(LocationID))

        objDB.FillData(TempDT, "AW_Location", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            location = TempDT.Rows(0).Item("Location").ToString
            StateID = TempDT.Rows(0).Item("StateId").ToString
        End If

        objDB.ClearParameter()
        TempDT = New Data.DataTable

        objDB.dbVariable.SQLString = "Select State, CountryId FROM AW_State WHERE StateId = @StateId"
        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(StateID))

        objDB.FillData(TempDT, "AW_State", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            state = TempDT.Rows(0).Item("State").ToString
            CountryID = TempDT.Rows(0).Item("countryId").ToString
        End If

        objDB.ClearParameter()
        TempDT = New Data.DataTable

        objDB.dbVariable.SQLString = "Select Country FROM AW_Country WHERE CountryId = @CountryId"
        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(CountryID))

        objDB.FillData(TempDT, "AW_Country", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            country = TempDT.Rows(0).Item("country").ToString
        End If

        objDB.CloseConnection()

        address = txtUnitNumber.Text.ToUpper & ", " & roadName & ", " & location & ", " & state & ", " & country

        lblAddress.Text = address
    End Sub

    Private Sub GetProjectName()
        If lblhidProjectId.Text <> String.Empty Then
            trProject.Visible = True
            Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
            Dim TempDT As New Data.DataTable

            objDB.OpenConnection()

            objDB.dbVariable.SQLString = "Select Project FROM AW_Project WHERE ProjectId = @ProjectId AND StatusDelete = 0"
            objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text))

            objDB.CloseConnection()

            objDB.FillData(TempDT, "AW_Project", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                lblProjectName.Text = TempDT.Rows(0).Item("Project").ToString
            End If
        Else
            trProject.Visible = False
        End If
    End Sub

    Private Function GetPropertyType(ByVal PropertyTypeId As String) As String

        Dim PropertyType As String = String.Empty
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "Select Type FROM AW_PropertyType WHERE TypeId = @TypeId AND StatusDelete = 0"
        objDB.AddParameter("TypeId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyTypeId))

        objDB.CloseConnection()

        objDB.FillData(TempDT, "AW_PropertyType", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            PropertyType = TempDT.Rows(0).Item("Type").ToString
        End If

        Return PropertyType
    End Function

    'Protected Sub btnCancelPreEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelPreEntry.Click
    '    Response.Redirect("propertylist.aspx")
    'End Sub

    Private Sub InsertRem_Old(ByVal propertyId As String, ByVal objDB As Database)
        objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_Property " &
            "(OId, PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, RTransactionId, STransactionId, SRAmt, " &
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " &
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " &
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " &
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " &
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " &
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " &
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " &
            "AuthorizeSaleRent, Remark, CommissionRemark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " &
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " &
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " &
            "OwnerAddress, ReferLister, RListStatus, SListStatus, RRelistStatus, SRelistStatus, CreateDate, StatusDelete, UpdateDate, UpdateWho, " &
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister, CPPlanNo, Floor, CompanyName, ViewContact, OtherContact, " &
            "LandlordCompanyName, LandlordViewContact, LandlordOtherContact, TitleNo, " &
            "SaleView, RentView, Latitude, Longitude,SaleGST, RentGST, SaleRemark, RentRemark " &
            ") " &
            "VALUES (@OId, @PropertyIdOLD, @RoadIdOLD, @ProjectIdOLD, @PropertyTypeID, @UnitNumberOLD, @ListType, @RTransactionId, @STransactionId, @SRAmt, " &
            "@SRPSF, @SRAskAmt, @SRAskPSF, @SRCreateDate, @SRYes, @SCAmt, @SCPSF, @SCAskAmt, @SCAskPSF, @SCCreateDate, @SCYes, @SLAmt, " &
            "@SLPSF, @SLASkAmt, @SLAskPSF, @SLCreateDate, @SLYes, @SIAmt, @SIPSF, @SIAskAmt, @SIAskPSF, @SICreateDate, @SIYes, @RRAmt, " &
            "@RRPSF, @RRASkAmt, @RRAskPSF, @RRCreateDate, @RRYes, @RCAmt, @RCPSF, @RCASkAmt, @RCAskPSF, @RCCreateDate, @RCYes, @RLAmt, " &
            "@RLPSF, @RLAskAmt, @RLAskPSF, @RLCreateDate, @RLYes, @RIAmt, @RIPSF, @RIASkAmt, @RIAskPSF, @RICreateDate, @RIYes, " &
            "@SListerId, @RListerId, @KeyInOffice, @ProjectRemark, @PropertyDesc, @SignboardStatus, @SignboardWhere, @SignboardWhen, " &
            "@SurveySheet, @QuitRent, @AssessmentBill, @PendingStatus, @PendingWho, @PendingWhen, @PendingWhy, @Tenure, @ListHoldExpired, " &
            "@Access, @AccessRemark, @Condition, @ConditionRemark, @Facing, @Zoning, @ZoningRemark, @Room, @Bathroom, @BestBuy, @ExclusiveStatus, @ExclusiveWho, @ExclusiveWhen, @ExclusiveEndDate, " &
            "@AuthorizeSaleRent, @Remark, @CommissionRemark, @Production1, @Production2, @Production3, @Admin1, @Admin2, @Admin3, @LAWidth, @LALength, " &
            "@LASF, @BUWidth, @BULength, @BUSF, @FloorLoad, @SECMK, @Ceiling, @Terrain, @District, @Lot, @Phase, @Furnished, @FurnishedRemark, " &
            "@Renovated, @RenovatedRemark, @Developer, @OwnerName, @OwnerMobile, @OwnerPhone, @OwnerFax, @OwnerEmail, " &
            "@OwnerAddress, @ReferLister, @RListStatus, @SListStatus, @RRelistStatus, @SRelistStatus, @CreateDateOLD, @StatusDeleteOLD, @UpdateDateOLD, @UpdateWhoOLD, " &
            "@LandlordName, @LandlordMobile, @LandlordPhone, @LandlordFax, @LandlordEmail, @LandlordAddress, @ReferLandlordLister, @CPPlanNo, @Floor, @CompanyName, @ViewContact, @OtherContact, " &
            "@LandlordCompanyName, @LandlordViewContact, @LandlordOtherContact, @TitleNo," &
            "@SaleView, @RentView,@Latitude, @Longitude, @SaleGST, @RentGST, @SaleRemark, @RentRemark " &
            ")"
        objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        objDB.AddParameter("PropertyIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(propertyId))
        objDB.AddParameter("RoadIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
        If lblhidProjectId.Text <> String.Empty Then
            objDB.AddParameter("ProjectIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text))
        Else
            objDB.AddParameter("ProjectIdOLD", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
        End If
        objDB.AddParameter("UnitNumberOLD", Data.SqlDbType.NVarChar, txtUnitNumber.Text.ToUpper)
        objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("StatusDeleteOLD", Data.SqlDbType.TinyInt, 0)
        objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidStaffId.Text))
        objDB.ExecuteQuery()
    End Sub

    Private Sub InsertUpdateContactOwner(ByRef objDB As Database)
        If txtMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " &
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtPhone.Text.Trim.ToUpper)
                End If
                If txtFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtFax.Text.Trim.ToUpper)
                End If
                If txtEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtEmail.Text.Trim.ToUpper)
                End If
                If txtAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 3)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtName.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId,Name, ProspectiveType, Mobile, Phone, " &
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " &
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 3)
                If txtName.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtName.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Sub InsertUpdateContactLandlord(ByRef objDB As Database)
        If txtLandlordMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " &
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtLandlordPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.Trim.ToUpper)
                End If
                If txtLandlordFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.Trim.ToUpper)
                End If
                If txtLandlordEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.Trim.ToUpper)
                End If
                If txtLandlordAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 4)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtLandlordName.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId, Name, ProspectiveType, Mobile, Phone, " &
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " &
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtLandlordPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 4)
                If txtLandlordName.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtLandlordName.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Function CheckPropertyExistence(ByVal listtype As String) As Boolean
        Dim ProjectFilter As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        If txtProjectName.Text = String.Empty Then
            ProjectFilter = " AND ProjectId IS NULL"
        Else
            ProjectFilter = " AND ProjectId = @ProjectId"
            objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text.Trim))
        End If

        'edit by tanchinteong 20140109
        'remove project if is not boss & admin
        If lblhidStaffType.Text = "1" Or lblhidStaffType.Text = "5" Then

        Else
            ProjectFilter = ""
        End If

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT PropertyId, UnitNumber, ListType, SRelistStatus, RRelistStatus FROM aw_property WHERE RoadId=@RoadId AND UnitNumber=@UnitNumber " &
                                    "AND StatusDelete=0 " & ProjectFilter
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
        objDB.AddParameter("UnitNumber", Data.SqlDbType.NVarChar, txtUnitNumber.Text.Trim.ToUpper)
        objDB.FillData(TempDT, "AW_UnitNumber", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()
        If TempDT.Rows.Count > 0 Then
            For Each row As Data.DataRow In TempDT.Rows
                If listtype = "3" Then
                    If row.Item("SRelistStatus").ToString = "" And row.Item("RRelistStatus").ToString = "" Then
                        Return False
                    Else
                        Return True
                    End If
                ElseIf listtype = "2" Then
                    If row.Item("RRelistStatus").ToString = "" Then
                        Return False
                    Else
                        Return True
                    End If
                ElseIf listtype = "3" Then
                    If row.Item("RRelistStatus").ToString = "" Then
                        Return False
                    Else
                        Return True
                    End If
                End If
            Next
        Else
            Return False
        End If
    End Function

    'Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
    '    If Session("Back") Is Nothing Then
    '        ClearAllFields()
    '        pnlEntry.Visible = False
    '        pnlPreEntry.Visible = True
    '        Response.Redirect("propertylist.aspx")
    '    Else
    '        Dim strBack As String = Session("Back").ToString
    '        Dim arr() As String = strBack.Split("ڡ")
    '        Response.Redirect(arr(0).ToString)
    '    End If
    'End Sub

    'Edit by tanchinteong 20130701
    Protected Sub btnUpdatePreEntry_Click(sender As Object, e As System.EventArgs) Handles btnUpdatePreEntry.Click
        'To change the detail of the property
        divError.Visible = False

        If ValidateSubmission() Then
            'Get the property id first.
            Dim currentpropertyid As String = lblhidPropertyId.Text

            'check unit number existence
            'check unit number format
            If CheckUnitExistence(txtUnitNumber.Text.Trim) Then 'Check the existence of new property details
                If True Then 'for admin & boss - skip checkUnitFormat(txtUnitNumber.Text.Trim)
                    'If not exist, allow change base on the property id
                    UpdateProperty(currentpropertyid)


                Else 'else, disallow change
                    divError.Visible = True
                    lblMsgError.Text = "Invalid unit number"
                End If
            End If
            'If lblhidISEFP.Text = "1" Then
            LoadProperty(lblhidPropertyId.Text, lblhidListType.Text)
            'End If
        Else
            Exit Sub
        End If
    End Sub

    Protected Sub ImageButtonEditAddress_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles ImageButtonEditAddress.Click
        'This is for the admin to edit adddress. Need to check if the new addresss has been existed fro the selection.
        'Edit by tanchinteong 20130630
        pnlPreEntry.Visible = True
        btnUpdatePreEntry.Visible = True
        btnSubmitPreEntry.Enabled = False
        ddlListType.Enabled = False
        GetddlCountry()
        GetddlState(ddlCountry.SelectedValue)
        GetddlLocation(ddlState.SelectedValue)
    End Sub

    Private Sub UpdateProperty(ByVal PropertyId As String)
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))

        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.AddParameter("PropertyTypeId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidPropertyTypeId.Text))
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidStaffId.Text))
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
            objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidRoadId.Text))
            If lblhidProjectId.Text <> String.Empty Then
                objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidProjectId.Text))
            Else
                objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            End If
            objDB.AddParameter("UnitNumber", Data.SqlDbType.NVarChar, txtUnitNumber.Text.ToUpper)
            objDB.dbVariable.SQLString = "UPDATE AW_Property SET RoadId=@RoadId, ProjectId=@ProjectId, UnitNumber=@UnitNumber,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho " & "WHERE PropertyId=@PropertyId"
            objDB.ExecuteQuery(False)
            objDB.DbTransCommit()
            GetAddress()
            GetProjectName()
        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
            udpMessage.Update()
            'Page.ClientScript.RegisterStartupScript(Me.GetType(), "divError", "$get('" + divError.ClientID + "').style.display='block';", True)
        End Try
    End Sub
End Class
